RE: [PHP] Name of Class' instance

From: Date: Wed, 07 Feb 2001 19:55:01 +0000
Subject: RE: [PHP] Name of Class' instance
Groups: php.general 
Request: Send a blank email to php-general+get-38611@lists.php.net to get a copy of this message
> > $joeBob = new myClass(); > > "myClass" can somehow know that "joeBob" is the name of > > it's instance? > > I'm thinking 'no', but would like verification. > I'm not aware of a way to do so. I'm curious why you'd want > to? If you want to pass "joeBob" to the class you can do so as the > parameter of one of the methods. This is what I ended up doing. Basically what I needed this for is I've got a class that prints out a blurb of javascript and a "<form>". I wanted to make it so that each instance of a class would work with it's own data. This would require that the name of the javascript function and the name of the form be different for each class instance. If I was able to get the name of the class, it would have been all good, I wouldn't have needed to add another paramter to the constructor. But since I cannot, I needed the additional paramter. The class is actually kind of cool. It sets up and executes the sorting of table columns based on a mySQL query. My problem was if I needed to tables using 2 different queries, when I clicked on a column heading in one table, it would try to sort that column in both classes, both queries. I got around this by adding the additional argument, as I mentioned above. > And my guess is that you already know, but if you want to refer to > a method or property of a class from within the class, you do using > syntax like $this->property_here. Yes, I already knew. :P Chris

« previous php.general (#38611) next »