note 94535 added to function.get-class-vars
| From: | ianitsky at gmail dot com | Date: | Tue, 10 Nov 2009 19:53:32 +0000 |
| Subject: | note 94535 added to function.get-class-vars | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162721@lists.php.net to get a copy of this message | ||
If you need get the child protected/private vars ignoring the parent vars, use like this:
<?php
class childClass extends parentClass {
private $login;
private $password;
public function __set($key, $val) {
if ($key == 'password')
$this->$key = md5($val);
else
$this->$key = $val;
}
}
class parentClass {
public $name;
public $email;
function __construct() {
$reflection = new ReflectionClass($this);
$vars = array_keys($reflection->getdefaultProperties());
$reflection = new ReflectionClass(__CLASS__);
$parent_vars = array_keys($reflection->getdefaultProperties());
$my_child_vars = array();
foreach ($vars as $key) {
if (!in_array($key, $parent_vars)) {
$my_child_vars[] = $key;
}
}
print_r($my_child_vars);
}
}
$child_class = new childClass();
?>
----
Server IP: 187.16.23.134
Probable Submitter: 200.136.27.3
----
Manual Page -- http://www.php.net/manual/en/function.get-class-vars.php
Edit -- https://master.php.net/note/edit/94535
Del: integrated -- https://master.php.net/note/delete/94535/integrated
Del: useless -- https://master.php.net/note/delete/94535/useless
Del: bad code -- https://master.php.net/note/delete/94535/bad+code
Del: spam -- https://master.php.net/note/delete/94535/spam
Del: non-english -- https://master.php.net/note/delete/94535/non-english
Del: in docs -- https://master.php.net/note/delete/94535/in+docs
Del: other reasons-- https://master.php.net/note/delete/94535
Reject -- https://master.php.net/note/reject/94535
Search -- https://master.php.net/manage/user-notes.php