Hehe why break your brain- give the class an id property - then you can have a getid method and do something like this
$id = $this->getid(); $this->fpLog = fopen("$id.log","w+"); get_object_vars only seems to return properties so its not gonna help you. I'm currently working on an object thang as well and what ive done where I have whole bunch of similar objects is to chuck them into a name=value array as they get created so I can find them and fiddle with them again. I have no idea if that helps you, or if its even good coding practice (formal training - wots that?) hey im also a n00b so don't take my word on it - actual mileage may vary :-P Cheers Will > -----Original Message----- > From: Marek Kilimajer [mailto:[EMAIL PROTECTED]] > Sent: 17 September 2002 11:49 AM > To: PHP > Subject: Re: [PHP] can you get the name of an object from > within it's own class? > > > 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 > > > > > > > > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php