note 44388 added to ref.classobj

From: Date: Wed, 04 Aug 2004 15:17:01 +0000
Subject: note 44388 added to ref.classobj
Groups: php.notes 
Request: Send a blank email to php-notes+get-73930@lists.php.net to get a copy of this message
To pillepop2003 at yahoo dot de: It seems to me if there really is no nice way to get the class name in an un-instanciated class, there is a workaround in PHP5 though using static/class variables. Example: <?php class myFoo { static $__ClassName = __CLASS__; static function getClassName() { return myFoo::$__ClassName; } }; class myFooExtended extends myFoo { function __construct() { myFooExtended::$__ClassName = __CLASS__; }; }; ?> However, you'll need to have at least instanciated an object of the class myFooExtended before calling getClassName or introduce some other initialization (the class variable will need to be set at some point to __CLASS__ in the sub-class). ---- Manual Page -- http://www.php.net/manual/en/ref.classobj.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44388 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44388&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44388&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#73930) next »