note 103562 added to function.get-parent-class

From: Date: Wed, 20 Apr 2011 15:36:22 +0000
Subject: note 103562 added to function.get-parent-class
Groups: php.notes 
Request: Send a blank email to php-notes+get-179003@lists.php.net to get a copy of this message
I wrote a simple function doing the reverse thing: get the children: <?php function get_child($instance, $classname) { $class = $classname; $t = get_class($instance); while (($p = get_parent_class($t)) !== false) { if ($p == $class) { return $t; } $t = $p; } return false; } abstract class A { function someFunction() { return get_child($this, __CLASS__); } } class B extends A { } class C extends B { } $c = new C(); echo $c->someFunction(); //displays B ?> ---- Server IP: 69.147.83.197 Probable Submitter: 84.58.189.139 ---- Manual Page -- http://www.php.net/manual/en/function.get-parent-class.php Edit -- https://master.php.net/note/edit/103562 Del: integrated -- https://master.php.net/note/delete/103562/integrated Del: useless -- https://master.php.net/note/delete/103562/useless Del: bad code -- https://master.php.net/note/delete/103562/bad+code Del: spam -- https://master.php.net/note/delete/103562/spam Del: non-english -- https://master.php.net/note/delete/103562/non-english Del: in docs -- https://master.php.net/note/delete/103562/in+docs Del: other reasons-- https://master.php.net/note/delete/103562 Reject -- https://master.php.net/note/reject/103562 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#179003) next »