Jump to content

How to use variable variables of object?


linus72982

Recommended Posts

I know how to use $$ and ${} to use variable variables, but how would I get the same functionality out of a variable that is storing an object name?

 

I have a function that is passed the name of an array of objects.  As you can guess, that name will change based on which portion of the program is calling

the function.  How would I use variable variables of objects in this instance?  Would it just be:

 

$this->${$objArrayName}->threadName = etc;

 

?

 

To make sure I'm not being misunderstood, I have 3 arrays of objects (replies, mainThreads, and stickies) and depending on which name I pass the function, I want it

to use $this->replies OR $this->mainThreads OR $this->stickies to apply properties of those objects to.

 

Thanks for any help.

 

-Adam

Link to comment
Share on other sites

I wouldn't think so, the same way that:

 

$foo = 'bar';
$bar = '1234';
echo $foo; // this would echo 'bar'
echo ${$foo}; // this would echo '1234'
// at least as far as I understand it

 

Or am I wrong about this?  I guess I can check after I get home from work, can't do it here.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.