note 101077 added to language.oop5.late-static-bindings
| From: | Anonymous at osu1 dot php dot net | Date: | Wed, 24 Nov 2010 17:22:08 +0000 |
| Subject: | note 101077 added to language.oop5.late-static-bindings | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174332@lists.php.net to get a copy of this message | ||
// THIS WORKED GREAT FOR ME:
abstract class ParentClass
{
static function parent_method()
{
$child_class_str = self::get_child_class();
eval("\$r = ".$child_class_str."::abstract_static();");
return $r;
}// CHILD MUST OVERRIDE TO PUT ITSELF INTO TRACE
protected abstract static function abstract_static();
private static function get_child_class()
{
$backtrace = debug_backtrace();
$num = count($backtrace);
for($i = 0; $i < $num; $i++)
{
if($backtrace[$i]["class"] !== __CLASS__)
return $backtrace[$i]["class"];
}
return null;
}
}
class ChildClass extends ParentClass
{
static function parent_method(){ return parent::parent_method(); }
protected static function abstract_static()
{
return __METHOD__."()";
}// From ParentClass
}
print "The call was: ". ChildClass::parent_method();
----
Server IP: 69.147.83.197
Probable Submitter: 98.240.236.17
----
Manual Page -- http://www.php.net/manual/en/language.oop5.late-static-bindings.php
Edit -- https://master.php.net/note/edit/101077
Del: integrated -- https://master.php.net/note/delete/101077/integrated
Del: useless -- https://master.php.net/note/delete/101077/useless
Del: bad code -- https://master.php.net/note/delete/101077/bad+code
Del: spam -- https://master.php.net/note/delete/101077/spam
Del: non-english -- https://master.php.net/note/delete/101077/non-english
Del: in docs -- https://master.php.net/note/delete/101077/in+docs
Del: other reasons-- https://master.php.net/note/delete/101077
Reject -- https://master.php.net/note/reject/101077
Search -- https://master.php.net/manage/user-notes.php