Re: Closures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux