Re: [RFC]

From: Date: Tue, 11 Feb 2020 16:39:00 +0000
Subject: Re: [RFC]
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-108487@lists.php.net to get a copy of this message
On Tue, 11 Feb 2020 at 16:27, Levi Morrison <levi.morrison@datadoghq.com> wrote: > > I have three immediate thoughts: > > 1. It should be fn or function; > reserving a new word even if it's > contextual is pointless here. > 2. It should support methods. > 3. It should return a closure, not a string. The reason is for > consistency with methods, where we want to capture the scope at the > time the closure is created, not ran. Imagine passing a private method > as a callback; if it was done via [$obj, > 'privatemethod'] then it > will fail at runtime, because the scope it's called in doesn't have > access. Hi, Levi, 1. Yes 2. Yes, I agree 3. Wouldn't it be the opposite?. E.g: class Foo { static function run_callable(callable $callable) { $callable(); } private static function private_function() { echo "bar"; } } Foo::run_callable( [ 'Foo', 'private_function' ] ); Currently, this is valid. However, the following is fatal: class Foo { static function run_callable(callable $callable) { $callable(); } private static function private_function() { echo "bar"; } } Foo::run_callable(Closure::fromCallable(['Foo', 'private_function'])); The same with functions. If "::function" would retrieve a closure, some code could breaking when people switch string function syntax( e.g: 'strlen' ) to "::function" syntax( strlen::function ). On other hand, other option is ::callable, This is different to ::function, because it would affect to other callables, so that, returns could be other( Closure )

« previous php.internals (#108487) next »