Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53036 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95387 invoked from network); 6 Jun 2011 15:55:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jun 2011 15:55:08 -0000 X-Host-Fingerprint: 208.107.178.23 host-23-178-107-208.midco.net Date: Mon, 06 Jun 2011 11:55:07 -0400 Received: from [208.107.178.23] ([208.107.178.23:2526] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F1/90-23189-A58FCED4 for ; Mon, 06 Jun 2011 11:55:07 -0400 Message-ID: To: internals@lists.php.net References: User-Agent: slrn/pre1.0.0-18 (Linux) X-Posted-By: 208.107.178.23 Subject: Re: $arr = array('Hello', 'world'); $arr(); From: weierophinney@php.net (Matthew Weier O'Phinney) On 2011-06-05, Felipe Pena wrote: > Reading our bug tracker I noticed a good feature request [1] from 2009 > which points to an interesting feature that I think makes sense for > us, since we are now working with $f() using objects and strings, and > the array('class', 'method') is an old known for call_user_func()-like > functions. > > So, I wrote a patch [2] that allow such behavior to be consistent with > arrays. See some examples: > > class Hello { > public function world($x) { > echo "Hello, $x\n"; return $this; > } > } > > $f = array('Hello','world'); > var_dump($f('you')); > > $f = array(new Hello, 'foo'); > $f(); > > All such calls match with the call_user_func() behavior related to > magic methods, static & non-static methods. > > The array to be a valid callback should be a 2-element array, and it > must be for the first element object/string and for the second string > only. (just like our zend_is_callable() check and opcodes related to > init call) > > Any thoughts? Huge +1 from me -- having to do constructs like the following have been a huge headache for me: if (is_callable($callback)) { if (is_object($callback) || is_string($callback)) { return $callback($arg); } return call_user_func($callback, $arg) } This would simplify that tremendously: if (is_callable($callback)) { return $callback($arg); } -- Matthew Weier O'Phinney Project Lead | matthew@zend.com Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc