note 78572 added to function.get-class

From: Date: Wed, 17 Oct 2007 20:21:04 +0000
Subject: note 78572 added to function.get-class
Groups: php.notes 
Request: Send a blank email to php-notes+get-131464@lists.php.net to get a copy of this message
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. ---- Server IP: 209.41.74.194 Probable Submitter: 166.89.16.240 ---- Manual Page -- http://www.php.net/manual/en/function.get-class.php Edit -- https://master.php.net/note/edit/78572 Del: integrated -- https://master.php.net/note/delete/78572/integrated Del: useless -- https://master.php.net/note/delete/78572/useless Del: bad code -- https://master.php.net/note/delete/78572/bad+code Del: spam -- https://master.php.net/note/delete/78572/spam Del: non-english -- https://master.php.net/note/delete/78572/non-english Del: in docs -- https://master.php.net/note/delete/78572/in+docs Del: other reasons-- https://master.php.net/note/delete/78572 Reject -- https://master.php.net/note/reject/78572 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131464) next »