note 89096 modified in function.get-called-class by danbrown
| From: | danbrown@php.net | Date: | Sat, 21 Feb 2009 18:47:08 +0000 |
| Subject: | note 89096 modified in function.get-called-class by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-150924@lists.php.net to get a copy of this message | ||
Here's a simple way of getting the inheritance tree of a class, no matter which class the
function was actually defined in. Will work as a static function method too.
<?php
class A {
public function get_class_tree(){
$cur_class = get_called_class();
do {
echo $cur_class;
}
while($cur_class = get_parent_class($cur_class));
}
}
class B {
}
class C {
}
$foo = new C();
$foo->get_class_tree();
?>
CBA
--was--
Here's a simple way of getting the inheritance tree of a class, no matter which class the
function was actually defined in. Will work as a static function method too.
---
class A {
public function get_class_tree(){
$cur_class = get_called_class();
do {
echo $cur_class;
}
while($cur_class = get_parent_class($cur_class));
}
}
class B {
}
class C {
}
$foo = new C();
$foo->get_class_tree();
---
CBA
http://php.net/manual/en/function.get-called-class.php