Re: RFC: alternative callback syntax
| From: | Ivan Enderlin @ Hoa | Date: | Thu, 20 Sep 2012 08:24:56 +0000 |
| Subject: | Re: RFC: alternative callback syntax | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-63186@lists.php.net to get a copy of this message | ||
On 19/09/12 20:21, Steve Clay wrote:
On 9/19/12 2:01 PM, Andrew Faulds wrote:PHP has recently introduced ::class to resolve a classname (namespace Foo; A::class // Foo\A). The “::” was originally a resolution operator for calls, but now, it is also used for names (which sounds good for me). Here, you propose the new notation ::function, which can be understood as: “resolve this function or method as a callable”. We stay in a resolution context. It is consistent regarding to the evolution of this operator. Another consistent notation is the cast: (callable) $obj->bar;. However, having { } around with & is absolutely horrible. It is an awful blend between references and dynamic variables, it is not consistent and error-prone when reading. Cheers :-). -- Ivan Enderlin Developer of Hoa http://hoa.42/ or http://hoa-project.net/ PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis) http://disc.univ-fcomte.fr/ and http://www.inria.fr/ Member of HTML and WebApps Working Group of W3C http://w3.org/(callable) is not usable as a cast (at least in 5.4.7): $a = (callable)'str'; // Parse error: syntax error, unexpected 'callable' (T_CALLABLE) This could work, and it makes sense to me at least.Some other ideas: $cb = (callable) $obj->bar;Ah, but (callable) that won't work for global functions, since (callable) is a cast, and$cb = {mysql_real_escape_string}; $cb = &{mysql_real_escape_string}; These notations are just horrible.