NYCPHP Meetup

NYPHP.org

[nycphp-talk] follow-on variable variables question

Adam Fields adam at digitalpulp.com
Fri Feb 13 18:51:17 EST 2004


James Wetterau wrote:

> Adam Fields says:
> ...
> 
>>$elementname = "element".$somelabel;
>>global $$elementname;
>>for ($count = 1; $count <= $vp[varcounter]; $varcount++) {
>>   $$elementname->add_subobject($vp[type], $vp[vname][$count], $vprop);
>>};
>>
>>This is a small chunk of code that lets you set the name for an object 
>>according to a rule, then execute a method of that object. The array 
>>values passed to the method are also dynamically named.
> 
> 
> Ok, but you can do all the above with array keys, so why not use
> those?

I believe the problem I had there was that the object already existed in 
the global context, and the above code was called as a callback from a 
function that I couldn't alter which didn't support passing arguments 
in. Possibly, I could have made the global named objects into an array 
of objects, which would have avoided this problem. I don't recall now if 
there's a reason why I couldn't do that.

Granted, this is a fringe case...




More information about the talk mailing list