how to perform dynamic cascading references ??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

how to perform dynamic cascading references ??

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: how to perform dynamic cascading references ??

Post 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?
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Re: how to perform dynamic cascading references ??

Post 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
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Re: how to perform dynamic cascading references ??

Post 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;
Post Reply