Re: Inconsistencies in callable, call_user_func and direct variable calls

From: Date: Thu, 19 Mar 2015 16:27:48 +0000
Subject: Re: Inconsistencies in callable, call_user_func and direct variable calls
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-85219@lists.php.net to get a copy of this message
Hi, 2015-03-19 17:17 GMT+01:00 S.A.N <ua.san.alex@gmail.com>: >> Then how would you write an callback containing an already constructed object? >> $a = [$object, 'method']; >> >> The alternative is unnecessarily cumbersome: >> $a = function($methodArg1, $methodArg2) use($object) { return >> $object->method($methodArg1, $methodArg2); }; > > $object->$methodName(...$args); You would still need an array to pass the information about the callback to another context. The syntax you detailed is not usable by the callable typehint and internal functions requiring a callback. No improvement made. The better alternative may be to deprecate strings as callbacks (if one should be deprecated at all) and always require a closure or or an array with one of the following signatures array(string); array(string, string); array(object, string) Another way to unify array and string callback may be to use the callable syntax and have it return a closure: callable('strlen'); callable($object, $methodName); callable('class', 'staticMethod')

« previous php.internals (#85219) next »