Kicked some code butt
…in PHP.
I am using objects in PHPv4 and have been trying to figure out how to get two special objects to be universally accessible by all other objects that might be declared (as siblings) under a universal object (Main…actually Page in this case).
The problem is the limited scope nature of objects.
I finally contrived a safe but ill-begotten means…
In Main, I instantiate the objects into global variables before assigning those objects by reference as properties of Main. Then, in sibling objects (and their prodgeny), their Constructor assigns those two specific objects by reference as properties of the sibling/prodgeny.
This means writing a base class with the proper methods, and then deriving all the remaining classes from that base.
I know this is not good OOP, but I also know that PHPv4 doesn’t do complete OOP, and I am willing to accept that this is a temporary workaround. It should be safe enough in execution even if it creates some nasty code dependencies.
I don’t plan on marketing my wares to the world..at least not yet.
Anyway, this delima has held my attention for a couple of days, off-n-on in my spare time. I’ve not seen anything quite like it on the Net (probably because its such a hideous technique…*shrug*). And I’m quite glad to have it now resolved!
Now I’m off to bed.
I think that was a code confession :o) LOL … The lecturer in me was tempted to grade your solution (or is that the smart arse in me LOL) If all else fails convalute the code so badly that no mere human will ever figure out what you did ;o)
Warning Comment
i have no idea what this means, but YAY for you!!!
Warning Comment
Warning Comment
That’s how I’ve done things in PHP as well. I’ve used inheritance from one of two base classes (Page and Module) because, as you said, PHP is not an OO language.
Warning Comment
Oooooooookay… *smacks computer-illiterate self soundly across face*
Warning Comment