Re: Closures
| From: | Ray Hauge | Date: | Wed, 19 Mar 2008 02:49:33 +0000 |
| Subject: | Re: Closures | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-271761@lists.php.net to get a copy of this message | ||
Nathan Nobbe wrote:
if we were going to see support for anything anonymous that i would welcome it would be anonymous objects and the ability to create an object on the fly from an interface as per java 5.I'm not sure if this would solve your problem (my lack of java knowledge is showing), but you can create objects either by creating a new stdClass() object, or by using (object)NULL. Example: <?php $object = (object) NULL; $object->test1 = 1; $object->test2 = 2; echo $object->test1 . "\n"; echo $object->test2; ?> After trying to add a way to call a function from an object variable, I have come to the conclusion that it's kinda ugly. <?php $obj = (object) NULL; $obj->test = 2; $obj->myTestFunc = "myTestFunc"; function myTestFunc () { return "test"; } echo call_user_func($obj->myTestFunc) . $obj->test; ?> Does anyone have a link to some documentation about the stdClass? All I could find was a bunch of bug reports and other stuff that wasn't what I was looking for. I would have thought there'd be a page for it in the manual, but I didn't find one there either. -- Ray Hauge www.primateapplications.com