note 57548 added to function.get-parent-class

From: Date: Fri, 07 Oct 2005 00:01:55 +0000
Subject: note 57548 added to function.get-parent-class
Groups: php.notes 
Request: Send a blank email to php-notes+get-96538@lists.php.net to get a copy of this message
tim at correctclick dot com wrote: <quote> A slightly more cryptic but faster get_ancestors function: <?php function get_ancestors ($class) { for ($classes[] = $class; $class = get_parent_class ($class); $classes[] = $class); return $classes; } ?> (The second part of the for is implicitly testing for $class != ""). Recursion is considerably slower than looping, so you probably want to use this function. Hope someone finds it useful. </quote> I would prefer this version, because it will create no duplicates: <?php function get_ancestors ($class) { $classes = array($class); while($class = get_parent_class($class)) { $classes[] = $class; } return $classes; } Greets, Dennis ?> ---- Manual Page -- http://www.php.net/manual/en/function.get-parent-class.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57548 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57548&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57548&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57548&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57548&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57548&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57548&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57548&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57548&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#96538) next »