Re: can you get the name of an object from within it's own class?
| From: | lallous | Date: | Tue, 17 Sep 2002 11:00:40 +0000 |
| Subject: | Re: can you get the name of an object from within it's own class? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-116612@lists.php.net to get a copy of this message | ||
even more...
what if I create $c1 as a global instance and then $c1 as a local instance
(inside a function) ?
won't c1.log overwrite c1.log ?
Elias
"Marek Kilimajer" <kilimajer@webglobe.sk> wrote in message
news:3D86FA6F.1020004@webglobe.sk...
> It's not possible, imagine
>
> $firstname = new flashPash();
> $secondname = $firstname;
>
> Now is the log name secondname.log or firstname.log. Use new property.
>
> Simon McKenna wrote:
>
> >Hi all,
> >
> >I'm new to the php world and have just finished building my first class,
> >
> >It works pretty well, but i've run into a quandary adding debug code,
> >my problem is thus:
> >
> >Many objects get created by this class, often in the same php script,
> >and the debug log is an actual file. At the moment i'm naming the file
> >after the name of the class, but what I would really like to do is name
> >the log file after the name of the object instantiated from the class.
e.g.
> >
> >class flashPash {
> >....
> > $this->fpLog = fopen("flashPash.log","w+");
> >....
> > function debugLog($LogMsg) {
> > if (($this->debug == true) && (!empty($this->fpLog)))
> > fwrite($this->fpLog,$LogMsg."\n");
> > }
> >}
> >
> >$fpObject = new flashPash();
> >$fpObject->debug = true;
> >....
> >
> >
> >so...is there a way I can get the variable name "fpObject" from within
> >flashPash itself? i.e. so I can make the logfile "fpObject.log" instead
> >of "flashPash.log"
> >
> > I realise it would be trivial to create a new property of the class to
> >store the debug log filename, but i'm hoping I can avoid this?
> >
> >"get_object_vars" & "get_class" appear to be heading in the right
> >direction...but not quite...so...any ideas? is this actually possible?
> >I kinda want to go down the hierarchical tree, instead of going up it :)
> >
> >thanks for any help. php rocks!
> >si
> >
> >
> >
> >
> >
> >
>