|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29291 get_class_vars() return names with NULLs
Submitted: 2004-07-21 10:48 UTC Modified: 2004-07-21 20:38 UTC
From: carl dot b at h2data dot com Assigned: helly (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.0.0 OS: *
Private report: No CVE-ID: None
 [2004-07-21 10:48 UTC] carl dot b at h2data dot com
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:
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-21 20:38 UTC]
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
Thank you for the report, and for helping us make PHP better.
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 18:01:25 2019 UTC