#29291 [Opn->Csd]: get_class_vars() return names with NULLs
| From: | helly@php.net | Date: | Wed, 21 Jul 2004 18:38:52 +0000 |
| Subject: | #29291 [Opn->Csd]: get_class_vars() return names with NULLs | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-63279@lists.php.net to get a copy of this message | ||
ID: 29291
Updated by: helly@php.net
Reported By: carl dot b at h2data dot com
-Status: Open
+Status: Closed
Bug Type: Zend Engine 2 problem
Operating System: *
PHP Version: 5.0.0
Assigned To: helly
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2004-07-21 10:48:04] carl dot b at h2data dot com
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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29291&edit=1