Hello, On Mon, Dec 29, 2008 at 6:00 AM, David Zülke <david.zue...@bitextender.com> 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ülke: >> [...] >>> >>> 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(); >> >> This is the same as the following: >> >> $obj = new stdClass(); >> $obj->method = 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 property > 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 > > > > -- Etienne Kneuss http://www.colder.ch Men never do evil so completely and cheerfully as when they do it from a religious conviction. -- Pascal -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php