note 92746 added to language.variables.variable

From: Date: Fri, 07 Aug 2009 04:23:57 +0000
Subject: note 92746 added to language.variables.variable
Groups: php.notes 
Request: Send a blank email to php-notes+get-159171@lists.php.net to get a copy of this message
// Sometimes it's necessary to retrieve the value of $this from within an object. // This solution dedicates a public var $ID to store a unique identifier for the object: class Someclass { public $ID; public function what_is_this() { return '$this is: ' . $this->get_varname(); } private function get_varname() { $this->ID = uniqid(); foreach($GLOBALS as $key => $val) { if (is_a($val,'Someclass')) { if ($val->ID === $this->ID) { return $key; break; } } } } } // example: $my_var_instance = new Someclass; echo $my_var_instance->what_is_this(); // returns '$this is: my_var_instance' ---- Server IP: 209.41.74.194 Probable Submitter: 76.168.206.254 ---- Manual Page -- http://www.php.net/manual/en/language.variables.variable.php Edit -- https://master.php.net/note/edit/92746 Del: integrated -- https://master.php.net/note/delete/92746/integrated Del: useless -- https://master.php.net/note/delete/92746/useless Del: bad code -- https://master.php.net/note/delete/92746/bad+code Del: spam -- https://master.php.net/note/delete/92746/spam Del: non-english -- https://master.php.net/note/delete/92746/non-english Del: in docs -- https://master.php.net/note/delete/92746/in+docs Del: other reasons-- https://master.php.net/note/delete/92746 Reject -- https://master.php.net/note/reject/92746 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159171) next »