Re: How to find the object...(clarification)
| From: | Plutarck | Date: | Mon, 23 Apr 2001 23:46:57 +0000 |
| Subject: | Re: How to find the object...(clarification) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-49959@lists.php.net to get a copy of this message | ||
Before anyone get's confused I thought I should note that $this won't work
because I need the name of the object for use _outside_ of the class itself
too.
For instance I have a group of about 30 functions in a seperate file which
directly modify $front_page. $front_page will now be inside of an object,
and I _could_ just change them to $pge->front_page, but here's the problem.
I'm doing all this so I can have variable function output. So for now I use
the object name $pge to output data, but in the future I may need to use
$xml or $pge_error. But I don't want to go through all the functions and
change the names, so I use a variable variable. But I don't know how to get
the variable variable name!
So what I want is to see what name $this is holding, then declare what comes
after $ as the value of a global variable which I will use in a variable
variable.
I know, I know, it's really complicated. But it really is the most
non-constraining way of going about it, as I'm probably going to use this
class many times in the future.
So I'm still stumped. Am I going to have to just use a hack-around till a
version of PHP includes such an odd class function, of which I know of know
other such existing function in any language? :(
--
Plutarck
Should be working on something...
...but forgot what it was.
""Plutarck"" <aemuli@spamclause-yahoo.com> wrote in message
news:9c21ks$cp$1@toye.p.sourceforge.net...
> 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.
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>