0

I used to code in Laravel, and I'm pretty good with it.

I've moved from VSCode to PhpStorm 2019.3, and it is enforcing me like it has intentions inside for language features, it gives me a little warning message that you should declare this closure method as static.

I know PhpStorm2019.3 fully supports PHP 7.4. So, the question is this, that should I always create closures functions as static like

Route::get('/', function () {
    return view('posts', [
        'posts' => Post::all()
    ]);
});

// without static closure
Route::get('/posts/{post}', function (Post $post) {
    return view('post', [
        'post' => $post
    ]);
});

// with static closure
Route::get('/posts/{post}', static function (Post $post) {
    return view('post', [
        'post' => $post
    ]);
});

and is it good practice or bad practice? Because I found PhpStorm the best IDE in the world for PHP and Laravel developers.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Danish Mehmood
  • 111
  • 1
  • 7
  • 1
    1) Please show the screenshot of the message with such a warning. A full message. Because I believe that this inspection comes from one of the custom plugins and not directly from PhpStorm core itself. 2) Yes, using `static` here makes sense, a better performance/memory usage in PHP (although since it's not defined inside the class it may not make a big difference here). **P.S.** Use Google Translate if you want to know a bit more about that: https://habr.com/ru/post/561550/ **P.P.S** Latest PhpStorm version is 2021.3 – LazyOne Dec 26 '21 at 18:51
  • @LazyOne, yes i have added two custom plugins Laravel and laravel_idea, and i can't post the screenshot with the current stackoverflow reputation, and yes it also shows me that it will be memory efficient and will have better performance. Should i add static everytime whenever i add a route?? – Danish Mehmood Dec 26 '21 at 18:57

0 Answers0