|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-07-21 20:38 UTC] helly@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 23:00:01 2025 UTC |
Description: ------------ The keys in the array returned by get_class_vars() contains NULLs if the field (or variable) is protected or private. A more exact description of the syntax of the keys is listed below. protected: "\x00*\x00<fieldname>" private: "\x00<classname>\x00<fieldname>" public: "<fieldname>" Ok, it's a way to determine the access modifiers of the fields, but as the strings starts with NULL, most PHP functions will think the string is empty as it begins with a null (null-terminated strings). Example is preg_match(). In any case, get_class_vars() isn't supposed to do this kind of work; so any hint of the access shouldn't be included. BTW, is get_class_vars() supposed to only return public fields? As the docs doesn't mentions it, I've assumed not. Reproduce code: --------------- <?php class MyClass { protected $AProtectedField = "orange"; private $APrivateField = "apple"; public $APublicField = "strawberry"; } $fields = get_class_vars('MyClass'); foreach($fields as $name => $value) { echo "$name : $value\n"; } ?> Expected result: ---------------- AProtectedField : orange APrivateField : apple APublicField : strawberry Actual result: -------------- \x00*\x00AProtectedField : orange \x00MyClass\x00APrivateField : apple APublicField : strawberry