|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26010 Bug on get_object_vars() function
Submitted: 2003-10-27 15:27 UTC Modified: 2003-11-10 16:01 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: rodrigo at intelligencegroup dot com dot br Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2003-10-28 (dev) 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:
Solve the problem:
40 + 4 = ?
Subscribe to this entry?

 [2003-10-27 15:27 UTC] rodrigo at intelligencegroup dot com dot br
The function get_object_vars() is getting back an array where public variables is ok, but private variables is being defined  with no key.

Reproduce code:
class A {
	private $a;
	public $b;

	public function A() {
		$this->a = "value of a";
		$this->b = "value of b";
$data = new A();
$objVars = get_object_vars($data);

Expected result:
array(2) { ["a"]=>  string(10) "value of a" ["b"]=>  string(10) "value of b" }

Actual result:
array(2) { [""]=>  string(10) "value of a" ["b"]=>  string(10) "value of b" }


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-29 13:34 UTC]
Verified. Refraining from adding a test case till beta2 roll-up.

 [2003-11-01 17:29 UTC] schlueter at phpbar dot de
This bug also appears when var_dump'ing an object - without using get_object_vars() with Beta2.
(With print_r() I get the property names where private and public ones are marked - that's even nicer than just the name.)

Reproduce code:
class foo {
    private   $bar1 = 'foobar1';
    protected $bar2 = 'foobar2';
    public    $bar3 = 'foobar3';

$foo = new foo();

Expected result:
object(foo)#2 (3) {
  string(6) "foobar1"
  string(6) "foobar2"
  string(6) "foobar3"

Actual result:
object(foo)#2 (3) {
  string(6) "foobar1"
  string(6) "foobar2"
  string(6) "foobar3"
 [2003-11-03 15:53 UTC]
Correct me if i'm wrong, but isn't the purpose of the PPP elements to prevent this behavior?  As i see it, this is the clearly an intended response of attempting to access the variables externally.  Like i said, i may be wrong...

~ Andrew Heebner
 [2003-11-03 21:13 UTC] rodrigo at intelligencegroup dot com dot br
Ok. But in this case the elements value should not be there too. Right? Anyway, if is possible to take privates and protected atributes with get_object_vars, you can't manipulate the values of the object's elements. I think that everything must be returned, as you can use this for something like serialize, or use to work with db, do somethings about polymorphism.

Probably my english is being dificult to understand. :)
 [2003-11-10 16:01 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Feb 19 12:01:26 2019 UTC