note 87772 added to function.get-class-vars

From: Date: Sat, 20 Dec 2008 23:53:22 +0000
Subject: note 87772 added to function.get-class-vars
Groups: php.notes 
Request: Send a blank email to php-notes+get-148390@lists.php.net to get a copy of this message
So I wanted to get a list of the public parameters in a child class using a static function pre-5.3.0 (< 5.3.0). In 5.3.0+ you would use the new 'static' like you would 'self' to get the late binding. <?php class childClass extends parentClass { public $id; public $name; public static function getFields() { return self::_getFields(__CLASS__); } } abstract class parentClass { public $idInParent; public $nameInParent; abstract public static function getFields(); final protected static function _getFields($className) { $rtn = array(); foreach (array_keys(get_class_vars($className)) as $var) { $rtn[] = $var; } return $rtn; } } var_dump(childClass::getFields()); ?> Results: array(4) { [0]=> string(2) "id" [1]=> string(4) "name" [2]=> string(10) "idInParent" [3]=> string(12) "nameInParent" } ---- Server IP: 208.69.120.35 Probable Submitter: 66.27.49.42 ---- Manual Page -- http://www.php.net/manual/en/function.get-class-vars.php Edit -- https://master.php.net/note/edit/87772 Del: integrated -- https://master.php.net/note/delete/87772/integrated Del: useless -- https://master.php.net/note/delete/87772/useless Del: bad code -- https://master.php.net/note/delete/87772/bad+code Del: spam -- https://master.php.net/note/delete/87772/spam Del: non-english -- https://master.php.net/note/delete/87772/non-english Del: in docs -- https://master.php.net/note/delete/87772/in+docs Del: other reasons-- https://master.php.net/note/delete/87772 Reject -- https://master.php.net/note/reject/87772 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148390) next »