RE: [PHP] How to find the object name in a class?
| From: | Boget, Chris | Date: | Tue, 24 Apr 2001 12:44:18 +0000 |
| Subject: | RE: [PHP] How to find the object name in a class? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-50056@lists.php.net to get a copy of this message | ||
> *sigh* I'm thinking so too ;(
> Doh!
> However, I have at least a usable hack around.
> In the constructor of your class, add:
> function Class ($object_name) {
> global $pge;
> $pge = $object_name;
> }
> Then when you use create a new object of that type you must use:
> $objectname = new Class('objectname');
Heh. This is exactly what I'm doing as it was the only work around
that I could find, too.
> Then in your code you just use ${$pge}-> to refer to it.
Yup. However, before I do this, I check to make sure $pge is valid
before I use it. Otherwise, all kinds of nastiness can occur.
What I'm doing this for is my error reporting class. I'm using a
wrapper function that calls my class' errorHandler() method since
you cannot specify a class method as the handler function. Kind
of funky. But doing this was the only way I could get around it.
> Sucks, doesn't it?
Yup. But I'm sure there is a reason for it. Kind of like whatever
the reason is that we cannot actually get a variable's name.
I.E.
$joe = "bob";
we cannot get that the above variable's name is "joe".
Oh, well.
Chris