note 128590 added to functions.first_class_callable_syntax

From: Date: Tue, 06 Jun 2023 15:53:01 +0000
Subject: note 128590 added to functions.first_class_callable_syntax
Groups: php.notes 
Request: Send a blank email to php-notes+get-220547@lists.php.net to get a copy of this message
There's a major gotcha with this syntax that may not be apparent until you use this syntax and find you're getting "Cannot rebind scope of closure created from method" exceptions in some random library code. As the documentation indicates, the first-class callable uses the scope at the point where the callable is acquired. This is fine as long as nothing in your code will attempt to bind the callable with the \Closure::bindTo method. I found this the hard way by changing callables going to Laravel's Macroable functionality from the array style to the first-class callable style. The Macroable functionality \Closure::bindTo calls on the callable. AFAIK, the only workaround is to use the uglier array syntax. ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.130 (proxied: 66.186.248.122) ---- Manual Page -- https://php.net/manual/en/functions.first_class_callable_syntax.php Edit -- https://main.php.net/note/edit/128590 Del: integrated -- https://main.php.net/note/delete/128590/integrated Del: useless -- https://main.php.net/note/delete/128590/useless Del: bad code -- https://main.php.net/note/delete/128590/bad+code Del: spam -- https://main.php.net/note/delete/128590/spam Del: non-english -- https://main.php.net/note/delete/128590/non-english Del: in docs -- https://main.php.net/note/delete/128590/in+docs Del: other reasons-- https://main.php.net/note/delete/128590 Reject -- https://main.php.net/note/reject/128590 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220547) next »