note 90202 added to function.get-parent-class

From: Date: Thu, 09 Apr 2009 19:28:48 +0000
Subject: note 90202 added to function.get-parent-class
Groups: php.notes 
Request: Send a blank email to php-notes+get-153031@lists.php.net to get a copy of this message
This little snippet to get the inheritance tree might be useful to someone. <?php header("Content-Type: text/plain;"); class Top { public function getParents($class=null, $plist=array()) { $class = $class ? $class : $this; $parent = get_parent_class($class); if($parent) { $plist[] = $parent; /*Do not use $this. Use 'self' here instead, or you * will get an infinite loop. */ $plist = self::getParents($parent, $plist); } return $plist; } } class Middle extends Top { } class Bottom extends Middle { } $o = new Bottom(); print_r($o->getParents()); ?> ---- Server IP: 64.71.164.2 Probable Submitter: 72.15.121.83 ---- Manual Page -- http://www.php.net/manual/en/function.get-parent-class.php Edit -- https://master.php.net/note/edit/90202 Del: integrated -- https://master.php.net/note/delete/90202/integrated Del: useless -- https://master.php.net/note/delete/90202/useless Del: bad code -- https://master.php.net/note/delete/90202/bad+code Del: spam -- https://master.php.net/note/delete/90202/spam Del: non-english -- https://master.php.net/note/delete/90202/non-english Del: in docs -- https://master.php.net/note/delete/90202/in+docs Del: other reasons-- https://master.php.net/note/delete/90202 Reject -- https://master.php.net/note/reject/90202 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#153031) next »