note 129679 added to functions.anonymous

From: Date: Wed, 31 Jul 2024 02:44:11 +0000
Subject: note 129679 added to functions.anonymous
Groups: php.notes 
Request: Send a blank email to php-notes+get-221452@lists.php.net to get a copy of this message
As of PHP 8.3.9 PHP doesn't allow type hinting within the use statement. Consider the following Laravel route: Route::get('/tags/{tag}', function (string $tag) use ($posts): View { $tagPosts = $posts->filter( function (Post $post) use ($tag): bool { return in_array($tag, $post->tags); } ); return view('tags.show', [ 'posts' => $tagPosts, 'tag' => $tag ]); }); As you can see I can make the code more verbose in the closures by type hinting the parameters and the return type. use however doesn't allow type hinting. ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.137 (proxied: 180.150.37.172) ---- Manual Page -- https://php.net/manual/en/functions.anonymous.php Edit -- https://main.php.net/note/edit/129679 Del: integrated -- https://main.php.net/note/delete/129679/integrated Del: useless -- https://main.php.net/note/delete/129679/useless Del: bad code -- https://main.php.net/note/delete/129679/bad+code Del: spam -- https://main.php.net/note/delete/129679/spam Del: non-english -- https://main.php.net/note/delete/129679/non-english Del: in docs -- https://main.php.net/note/delete/129679/in+docs Del: other reasons-- https://main.php.net/note/delete/129679 Reject -- https://main.php.net/note/reject/129679 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221452) next »