php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: carl dot b at h2data dot com
New email:
PHP Version: OS:

 

 [2004-07-21 10:48 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-21 20:38 UTC] helly@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC