note 78572 deleted from function.get-class by felipe

From: Date: Sun, 16 Dec 2007 12:16:48 +0000
Subject: note 78572 deleted from function.get-class by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133686@lists.php.net to get a copy of this message
Note Submitter: colin at shuaige dot org ---- get_class() seems to actually return information about a prototype version of the class when called using $this as opposed to the working instance of the class. You must use "$this->$name" to get the info from this instance. For example: class myClass { var myVar = "foo"; function myClass () { $this->myVar = "bar"; } function testClass () { $vars = get_class_vars(get_class($this)); echo "Var myVar = ".$vars["myVar"].'<br/>'; } function testClassAgain () { $vars = get_class_vars(get_class($this)); echo "Var myVar = ".$this->myVar; } } $instance = new myClass(); $instance->testClass(); $instance->testClassAgain(); Outputs: foo bar This makes sense, but surprised me the first time I saw it.

« previous php.notes (#133686) next »