php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80019 get_object_vars() does not return uninitialized properties
Submitted: 2020-08-26 10:22 UTC Modified: 2020-08-28 08:28 UTC
From: brego at hey dot com Assigned: cmb (profile)
Status: Not a bug Package: Documentation problem
PHP Version: 7.4.9 OS: macOS 10.15.6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: brego at hey dot com
New email:
PHP Version: OS:

 

 [2020-08-26 10:22 UTC] brego at hey dot com
Description:
------------
---
From manual page: https://php.net/function.get-object-vars
---

I realize the code works as intended#1 however the documentation of get_object_vars does not mention that uninitialized object properties will not be returned.


#1: https://bugs.php.net/bug.php?id=79236

Test script:
---------------
class A {
    public function get() {
        var_dump(get_object_vars($this));
    }
}

class B extends A {
    public $foo;
    public $bar = 'bar';
    public string $baz;
}

$b = new B;

$b->get();

Expected result:
----------------
array(3) {
  ["foo"]=>
  NULL
  ["bar"]=>
  string(3) "bar"
  ["baz"]=>
  uninitialized // <- or something different?
}

Actual result:
--------------
array(2) {
  ["foo"]=>
  NULL
  ["bar"]=>
  string(3) "bar"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-08-28 08:28 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-08-28 08:28 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The documentation states:

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

$baz is not accessible[1], though.

[1] <https://3v4l.org/A0jIq>
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Nov 25 13:01:25 2020 UTC