php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #45469 get_object_vars($this) varies from what documentation says
Submitted: 2008-07-09 17:42 UTC Modified: 2008-11-05 10:42 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: czaries at gmail dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: WinXP
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: czaries at gmail dot com
New email:
PHP Version: OS:

 

 [2008-07-09 17:42 UTC] czaries at gmail dot com
Description:
------------
The documentation for the get_object_vars() function clearly states "Gets the public properties of the given object", however this function will actually return all the properties it has ACCESS TO, including properties within the protected and private scope.

This is most clearly evident when using "get_object_vars($this)" inside an object instance.  Either the documentation needs to be changed to reflect the actual behavior of this function, or a boolean flag needs to be added that will alter the behavior of this function to produce the expected result without breaking backwards compatibility.

I would really like to see a second parameter added to this function, because I was intending to use this function to get only the public properties of an object, as the documentation stated.

Reproduce code:
---------------
<?php
class Testing {
    private $dontShowMe = true;
    protected $dontShowMeEither = true;
    public $showMe = true;

    public function getData() {
        return get_object_vars($this);
    }
}

$test = new Testing();
print_r($test->getData());
?>

Expected result:
----------------
Array ( [showMe] => 1 )

Actual result:
--------------
Array ( [dontShowMe] => 1 [dontShowMeEither] => 1 [showMe] => 1 )

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-09 18:13 UTC] felipe@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2008-07-18 14:57 UTC] czaries at gmail dot com
Thanks for the update and for altering the language in the documentation.  You did miss one line though :)

http://www.php.net/get_object_vars

get_object_vars

(PHP 4, PHP 5)

get_object_vars ? Gets the public properties of the given object
Description
array get_object_vars ( object $object )

Gets the accessible non-static properties of the given object according to scope.


The descriptor line above the blue boxes has not been updated like the one in the "Description" blue box has.
 [2008-11-05 10:42 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"Gets the properties of the given object"
 [2020-02-07 06:10 UTC] phpdocbot@php.net
Automatic comment on behalf of felipe
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=a72591107c41b7e7c907d051339013432b0ccdf3
Log: Fixed bug #45469 (get_object_vars($this) varies from what documentation says)
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 09:00:02 2026 UTC