Sorry about the title, but it was the most descriptive I could be... =) Pull up a chair and a coffee, this is a long one. I just hope I can explain it right...
Here's the story: the reality is much much more complex than this, but for simplicity's sake: I have 3 objects created in a script, lets call them $obj_base for stuff like email validation and type checking; $obj_session for data like username, account settings, and so on; and another called $obj_showUserData, which pulls the user info from a database and displays it nicely. Straightforward so far (if a little contrived), yes?
Here's where the trouble starts. Say I'm hooking along in $showUserData, and I get to their email address. Say I want to validate it, using the validateEmail() function in the $obj_base object. How do I talk to $obj_base from here?
Calling $obj_base->validateEmail() obviously wouldn't work, because the $obj_showUserData doesn't know it exists, being the nice and tidy object that it is.
Sure, I could make $obj_base and $obj_session global, or pass references like &$obj_base to the showUserData constructor, but then if I make a new class later on that I also use all over the place, I'd have to go through every class and add it as either a global, or a reference, and that sucks for maintaining. I'm talking a 12,000+ line codebase with hundreds of classes here. There's also the problem of having to call global in every.single.method of the class... This is my main quibble - I don't want to have to hard-code the objects I want to access - what if their name changes, or I need to add more? Maintainability out the window...
Use inheritence, you say? No, sir. Since $obj_base is used so often, all the objects in each script (about 10 in the real world, sometimes more) would have to be it's children, and again for $obj_session; and that's a massive memory suck for one - and does PHP even do multiple inheritance? Not to mention that if it were something like $obj_session, I'd end up with 10 copies of the same properties in different objects - what if I wanted to change one? I'd have to go through every object and change them all!
The gotcha goes for a property stored in $obj_session - if I want to grab that from inside $obj_base, how on earth do I do it without hardcoded globalling of the whole object?!
In ActionScript (cue flaming), there is the marvellous root property. It means the base or global namespace of the movie, and ideally it's what I need - to call something (in $obj_showUserData) like $root.$obj_base->validateEmail(). If a kludge on a kludge thing like ActionScript can do this, surely a real language like PHP can? There has to be a way to have one object use a method from another... at least I hope so, or OO isn't as attractive as it was.
Abbreviation: how do I pass data to or call methods from a different object in the root namespace, without going through the "globalize/create reference to the object in every function you need to" rigmarole?
Sorry about the novel and I hope I've explained myself well enough (it's hard to put something like this into English correctly and concisely), but I'm at my wit's end on this one - Google hasn't helped, and this seems like very very basic functionality to be missing from the OOP model...