How to find the object name in a class?
| From: | Plutarck | Date: | Mon, 23 Apr 2001 19:58:30 +0000 |
| Subject: | How to find the object name in a class? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-49929@lists.php.net to get a copy of this message | ||
I've been using a function to output HTML to the user's browser, and now my
use has made it neccessary to put it all inside a class.
All's going find and dandy and I've got it all working. However one of it's
variables is $front_page.
Now in other pages there are references to $front_page, and I want to change
them to something like $objectname->front_pagee.
The problem is that I can't know what the object will be named ahead of
time!
So my hack-around is in the class constructor I set a global variable called
$pge with the value submitted to the constructor. So someone would do this:
$somename = new Display(somename);
But if someone typos the and the name of the variable is different from the
one submitted to the constructor, all the code will break! That's because
I'm using a variable variable to refer to $front_page, like this:
${$pge}->front_page
I told you it was a hack-around, and it isn't a good one.
So is there ANY way to get the name of the object in PHP code without
knowing the name of the object ahead of time?
I'm really stumped!
--
Plutarck
Should be working on something...
...but forgot what it was.