Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42394 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44958 invoked from network); 29 Dec 2008 07:01:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Dec 2008 07:01:52 -0000 Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 72.14.220.154 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 72.14.220.154 fg-out-1718.google.com Received: from [72.14.220.154] ([72.14.220.154:53248] helo=fg-out-1718.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4C/44-18017-DD578594 for ; Mon, 29 Dec 2008 02:01:50 -0500 Received: by fg-out-1718.google.com with SMTP id 16so1581058fgg.23 for ; Sun, 28 Dec 2008 23:01:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references :x-google-sender-auth; bh=yygs1/DfyU2uzwpkMu1YOZyyo+gc8GFXNVY5jnJOJkM=; b=KDIOhpaT6xxtH0TcPvu70NDY9H12MOZ10sZntfATSl/dK67pYh89YavIjJ8di8SfjO JYQdg1gzV1qNAQcxkIS34Vqhglc+qCTg6HpS+oVDQWwCmyIL012xUdXR+AZ8MHKZ0Ybw 9YC3YjtmE9MLUxCFlJ/nzhhINgCgt+tXYhSiA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references:x-google-sender-auth; b=jjF3FlJni21V7Yckww9ClfQsUI1aNjkeIBDmUsCbTOIWntiUeoYaU9JqXT0RHV5RYR +RFPrpKAOjqG/AW8jndsDCuR17xMpWSdinNNkYCj2JlJLEenZihM5f+vEc2GdRzgfyJb wR4LH/yzsCt8je+RH9mIR9xj9ZjhLbxfpAvxw= Received: by 10.86.95.8 with SMTP id s8mr7908989fgb.79.1230534106433; Sun, 28 Dec 2008 23:01:46 -0800 (PST) Received: by 10.86.81.13 with HTTP; Sun, 28 Dec 2008 23:01:46 -0800 (PST) Message-ID: Date: Mon, 29 Dec 2008 08:01:46 +0100 Sender: ekneuss@gmail.com To: "=?ISO-8859-1?Q?David_Z=FClke?=" Cc: "Lars Strojny" , "Stanislav Malyshev" , "PHP Internals" In-Reply-To: <1943543F-9AE0-4F90-8417-F39175B19EB6@bitextender.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <08AA10DA-2704-415C-8A8C-893C89990DC1@bitextender.com> <1230181883.12121.9.camel@localhost> <1943543F-9AE0-4F90-8417-F39175B19EB6@bitextender.com> X-Google-Sender-Auth: 4cbd000730610614 Subject: Re: [PHP-DEV] __invoke() weirdness From: webmaster@colder.ch ("Etienne Kneuss") Hello, On Mon, Dec 29, 2008 at 6:00 AM, David Z=FClke wrote: > On 25.12.2008, at 06:11, Lars Strojny wrote: > >> Hi David, >> >> Am Dienstag, den 23.12.2008, 17:02 +0100 schrieb David Z=FClke: >> [...] >>> >>> This gives a fatal "Call to undefined method DateTime::getAtom()" >>> $d =3D new DateTime(); >>> $d->getAtom =3D Curry::create(array($d, 'format'), DATE_ATOM); >>> echo $d->getAtom(); >> >> This is the same as the following: >> >> $obj =3D new stdClass(); >> $obj->method =3D function() { >> return "foo"; >> }; >> $obj->method(); >> >> The first "method" is a property, the call to "method" is - well - a >> method call. Because PHP separates methods and properties in the class >> entry structure - and because we have magic methods like __set, __get >> and __call, there is no efficient and logical way how to search for >> properties with closure instances when a method is not found. We >> discussed that before and decided to let closures go out into the wild >> and think about adding a solution for prototype alike inheritance later. > > I realize that, but I guess it's pretty inconsistent, as I can do > - $func(); > - $func->__invoke(); > - $obj->func->__invoke(); > but not > - $obj->func(); > > That was my point; I'm aware of potential reasons for this behavior (like > what Stas pointed out). Sorry for the confusion ;) > > Is it going to be like this forever? Stas said "there is no way to > distinguish". Isn't that a parser issue that should be gone now with the > switch to re2c? Wouldn't it be possible to just do a lookup for a propert= y > that is an object with __invoke if the method was not found? Well, this is not a parser problem (so re2c, which actually is the lexer, won't help). Additionally: looking for a property when a method is not found would break code relying on __call() to be called on those cases. Finally, note that you can do that in userland using something looking like= : public function __call($name, $args) { return call_user_func_array(array($this->$name, "__invoke"), $args); } Regards, > > - David > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > > > --=20 Etienne Kneuss http://www.colder.ch Men never do evil so completely and cheerfully as when they do it from a religious conviction. -- Pascal