|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #73715 Undocumented change in 7.0 of call_user_func + get_object_vars
Submitted: 2016-12-11 01:05 UTC Modified: 2016-12-15 15:22 UTC
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: love at sickpeople dot se Assigned:
Status: Open Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-12-11 01:05 UTC] love at sickpeople dot se
In PHP 5 it was possible to invoke get_object_vars() with call_user_func() in order to get only public variables. This is no longer the case.

 1) I can't find any documentation about this change on the pages for get_object_vars, call_user_func OR the migration for 7.0 (grepping for 'scope')

 2) This upvoted comment introduced the hack with call_user_func() to me:

I suggest two things

 A) Add an editor note on the comment mentioned in 2). Tell that this only works in PHP 5

 B) Add more info in or

  - I presume this is not a change in call_user_func() or get_object_vars() themselves. I was not able to find what the source of this change actually is, hence more info of *some kind* is requested.

Test script:
class M
    protected $A = 'foo';

    private $B = 'bar';

    public Function dump ()
        var_dump (
            array_keys (get_object_vars ($this)),
            array_keys (call_user_func ('get_object_vars', $this))

        return $this;


 var_dump (get_object_vars ((new M)->dump ()));

Expected result:

 - The result between PHP 5 and PHP 7 differs


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-11 01:09 UTC] love at sickpeople dot se
I posted the wrong links to the migration. I have verified that I checked the guide for 7.0 in 1).

Correct links
 [2016-12-11 16:04 UTC]
The behavioral change *might* have been introduced with commit de306e70[1] and *might* not even have been intentional.

[1] <;a=commit;h=de306e70882dd7dd04ea952ef3c665304837c3be>
 [2016-12-15 15:22 UTC]
@cmb: It was not intentional to have different behaviors between when call_user_func() is using the function vs the opcode in 7.0. (see

That was fixed in 7.1; and now call_user_func() will always preserve scope.

A workaround instead of call_user_func() would be:
(function($obj) { return get_object_vars($obj); })->call(new class {}, $this)
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 21 08:01:34 2024 UTC