Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42426 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95076 invoked from network); 31 Dec 2008 19:15:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Dec 2008 19:15:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=helly@php.net; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 85.214.94.56 as permitted sender) X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 85.214.94.56 aixcept.net Linux 2.6 Received: from [85.214.94.56] ([85.214.94.56:39952] helo=h1149922.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 35/52-01584-8E4CB594 for ; Wed, 31 Dec 2008 14:15:53 -0500 Received: from MBOERGER-ZRH.corp.google.com (229-122.107-92.cust.bluewin.ch [92.107.122.229]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by h1149922.serverkompetenz.net (Postfix) with ESMTP id 6EB6911F000; Wed, 31 Dec 2008 20:15:49 +0100 (CET) Date: Wed, 31 Dec 2008 20:12:59 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <8710064882.20081231201259@marcus-boerger.de> To: Lars Strojny CC: Marcus Boerger , =?iso-8859-15?Q?David_Z=FClke?= , PHP Internals In-Reply-To: <1230746348.25966.3.camel@localhost> References: <08AA10DA-2704-415C-8A8C-893C89990DC1@bitextender.com> <868073456.20081231173818@marcus-boerger.de> <1230746348.25966.3.camel@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Re: [PHP-DEV] __invoke() weirdness From: helly@php.net (Marcus Boerger) Hello Lars, Wednesday, December 31, 2008, 6:59:08 PM, you wrote: > Hi Markus, > have you measured the performance impact in a class with - say - ten > methods? And what to do with __get() and __call()? How are the > prioritized in the method resolve order? Translated into user code we now have: public function __zend_call($name, $args) { // Added property lookup if (isset($this->$name)) { // may call __isset $callable = $this->$name; // may call __get if (is_callable($callable)) { return call_user_func_array($callable, $args); } } // Original behavior: // Check for __call if (method_exists($this, '__call')) { return $this->__call($name, $args); } // error error_log('Function ' . __CLASS__ . '::' . $name . ' not found'); return NULL; } As to the performance impact. We add one additional hash-lookup per method call on a default class for a non found function. So whenever we would normally call __call we add an additional lookup. > cu, Lars > Am Mittwoch, den 31.12.2008, 17:38 +0100 schrieb Marcus Boerger: >> Hello David, >> >> Tuesday, December 23, 2008, 5:02:43 PM, you wrote: >> >> > Hi folks, >> >> > I played with __invoke today: >> >> > class Curry >> > { >> > protected $callable; >> > protected $args; >> >> > public static function create($callable) >> > { >> > $curry = new self($callable, array_slice(func_get_args(), 1)); >> > return $curry; >> > } >> >> > protected function __construct($callable, $args) >> > { >> > $this->callable = $callable; >> > $this->args = $args; >> > } >> >> > public function __invoke() >> > { >> > return call_user_func_array($this->callable, array_merge($this- >> >>args, func_get_args())); >> > } >> > } >> >> > However, it doesn't work consistently. >> >> > This works fine: >> > $d = new DateTime(); >> > $getAtom = Curry::create(array($d, 'format'), DATE_ATOM); >> > echo $getAtom(); >> >> > This gives a fatal "Call to undefined method DateTime::getAtom()" >> > $d = new DateTime(); >> > $d->getAtom = Curry::create(array($d, 'format'), DATE_ATOM); >> > echo $d->getAtom(); >> >> > Is that intentional? >> >> So far it is. Yet I as much as you do not like the inconsistency. So I >> spend a little bit on providing the following patch that should do what >> you were looking for. >> >> The disadvantage: Calling properties is case sensitive while calling >> methods isn't. But since this has nothign to do with this patch and the >> patch only increases consistency I am all for applying it. >> >> Comments? Lukas/Johannes? >> >> Oh I hate that case insensitivity.... and inconsistency.... >> >> > Cheers, >> >> > David >> >> >> >> >> >> Best regards, >> Marcus >> -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php Best regards, Marcus