|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-04-03 14:05 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 15 06:00:01 2025 UTC |
Description: ------------ When using get_class_vars() inside a class it does not act how it is documented on php.net. But that is not the main problem. It seems as if get_class_vars() is creating some strange identifiers in its resulting array, making it effictively unusable. I already found out, that protected members are prefixed by '*' and private members are prepended with the classname, but the identifier-string is longer, than it should be. When accessing my test-program with a web-browser there are some weird (probably multibyte) characters at the end of identifiers for protected and private members, which don't show up in a terminal using the CLI binary. I'm not sure if this behaviour is expected (since it's not documented), but there would be no point in having get_class_vars() returning something that cannot be used subsequently. And IMHO the Reflection-API behaves very differently; e.g. fetching class attributes in at least 5 lines (via Reflaction API) vs. a one-line call to fetch all attributes (via get_class_vars()). Reproduce code: --------------- class test { public $foo1; protected $foo2; private $foo3; public function __construct() { $this->foo1 = 'public'; $this->foo2 = 'protected'; $this->foo3 = 'private'; } } $bar = array_keys(get_class_vars('test')); var_dump($bar); Expected result: ---------------- array(3) { [0]=> string(4) "foo1" [1]=> string(5) "*foo2" [2]=> string(8) "testfoo3" } Actual result: -------------- array(3) { [0]=> string(4) "foo1" [1]=> string(7) "*foo2" [2]=> string(10) "testfoo3" }