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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
9 + 1 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Thu Apr 18 23:01:27 2024 UTC