php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #29509 get_class_vars() returns unusable information
Submitted: 2004-08-03 19:45 UTC Modified: 2006-04-03 14:05 UTC
Votes:4
Avg. Score:4.2 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%)
Same OS:4 (100.0%)
From: ap at ath0 dot org Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 5.0.0 OS: Linux 2.6.7
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ap at ath0 dot org
New email:
PHP Version: OS:

 

 [2004-08-03 19:45 UTC] ap at ath0 dot org
Description:
------------
When using get_class_vars() inside a class it does not act how it is documented on php.net. But that is not the main problem. It seems as if get_class_vars() is creating some strange identifiers in its resulting array, making it effictively unusable.

I already found out, that protected members are prefixed by '*' and private members are prepended with the classname, but the identifier-string is longer, than it should be.
When accessing my test-program with a web-browser there are some weird (probably multibyte) characters at the end of identifiers for protected and private members, which don't show up in a terminal using the CLI binary.

I'm not sure if this behaviour is expected (since it's not documented), but there would be no point in having get_class_vars() returning something that cannot be used subsequently.
And IMHO the Reflection-API behaves very differently; e.g. fetching class attributes in at least 5 lines (via Reflaction API) vs. a one-line call to fetch all attributes (via get_class_vars()).

Reproduce code:
---------------
class test {
    public $foo1;
    protected $foo2;
    private $foo3;
    public function __construct() {
        $this->foo1 = 'public';
        $this->foo2 = 'protected';
        $this->foo3 = 'private';
    }
}
$bar = array_keys(get_class_vars('test'));
var_dump($bar);


Expected result:
----------------
array(3) {
  [0]=>
  string(4) "foo1"
  [1]=>
  string(5) "*foo2"
  [2]=>
  string(8) "testfoo3"
}


Actual result:
--------------
array(3) {
  [0]=>
  string(4) "foo1"
  [1]=>
  string(7) "*foo2"
  [2]=>
  string(10) "testfoo3"
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-03 14:05 UTC] tony2001@php.net
Fixed long time ago.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 07:01:31 2025 UTC