note 92757 added to function.get-called-class

From: Date: Fri, 07 Aug 2009 13:53:03 +0000
Subject: note 92757 added to function.get-called-class
Groups: php.notes 
Request: Send a blank email to php-notes+get-159185@lists.php.net to get a copy of this message
If you call a static getInstance() function to create a instance of a class from another class, this function have to be static, if it is not static the original name of the caller class and not of the current class get returned. example: <?php class a { function getXName() { return x::getClassName(); } function getXStaticName() { return x::getStaticClassName(); } } class b extends a { } class x { public function getClassName() { return get_called_class(); } public static function getStaticClassName() { return get_called_class(); } } $a = new a(); $b = new b(); echo $a->getXName(); // will return "a" echo $b->getXName(); // will return "b" echo $a->getXStaticName(); // will return "x" echo $b->getXStaticName(); // will return "x" ?> ---- Server IP: 81.223.20.5 Probable Submitter: 213.47.67.24 (proxied: 213.47.67.24) ---- Manual Page -- http://www.php.net/manual/en/function.get-called-class.php Edit -- https://master.php.net/note/edit/92757 Del: integrated -- https://master.php.net/note/delete/92757/integrated Del: useless -- https://master.php.net/note/delete/92757/useless Del: bad code -- https://master.php.net/note/delete/92757/bad+code Del: spam -- https://master.php.net/note/delete/92757/spam Del: non-english -- https://master.php.net/note/delete/92757/non-english Del: in docs -- https://master.php.net/note/delete/92757/in+docs Del: other reasons-- https://master.php.net/note/delete/92757 Reject -- https://master.php.net/note/reject/92757 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159185) next »