Page 1 of 1

how to perform dynamic cascading references ??

Posted: Mon Feb 25, 2008 2:33 am
by PHPycho
Hello forums!!
I would like to how to access nested objects
supppose i had an array

Code: Select all

$array = array("parent_obj", "child_obj1", "child_obj2");
I would like to perform referencing as per array ie

Code: Select all

$this->parent_obj->child_obj1->child_obj2;
I dont know how to perform dynamic cascading references.
Can anybody make a help on this.
Any help / comment/ suggestions are warmly welcome.

Re: how to perform dynamic cascading references ??

Posted: Mon Feb 25, 2008 2:48 am
by Chris Corbyn
Is "dynamic cascading references" a real term? Sounds scary 8O

I'm not sure what you're trying to do. Do you mean you want to access an element of an array by traversing all previous elements first?

Re: how to perform dynamic cascading references ??

Posted: Mon Feb 25, 2008 3:05 am
by PHPycho
Do you mean you want to access an element of an array by traversing all previous elements first?
ya thats what i want

Re: how to perform dynamic cascading references ??

Posted: Mon Feb 25, 2008 5:29 am
by PHPycho
Thanks i got it working by performing as:

Code: Select all

$element = '';
foreach ($array as $obj){
    $element .= '->'.$obj;
}
$element = trim($element, "->");       
eval('$return = $this->'.$element.';');   
return $return;