Suppose I have an object in PHP $o, about which I can get $o->a->b, or maybe $0->c[‘d’].
Is there a way of storing these as sort of address for handling elsewhere?
What I have is that at several different places I need to process different properties of the object, but in the same way.
So what I’d like to do is build a collection of addresses as I go along, and then hand them all to a single function which goes through them all and does the processing.
Eg:
$o->a = ‘red’;
$o->b->c = ‘red’;
$o->d[‘e’] = ‘red’;
… and I want to change all ‘red’ to ‘green’, but those particular keys and properties may change depending on circumstances.
You can do this:
But not this:
Alternatively, you can create references to the variables, like this: