|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-06-18 13:42 UTC] iamonyourroof at gmail dot com
Description: ------------ Dear, the following code has a different output on php 7.0.20 vs php 7.1.0. It includes protected variables in the output, which is not what you would expect. It seems like the scope for call_user_func has changed between these php versions. If this change was on purpose, should it not have been documented as an item on the list of incompatible changes? http://php.net/manual/en/migration71.incompatible.php Test script: --------------- <?php namespace crm; class et{ protected $table = "b"; public $field = "d"; private $x = "private!"; public function dump(){ var_dump( call_user_func('get_object_vars', $this) ); } } $et = new et(); echo phpversion()."\n"; $et->dump(); Expected result: ---------------- private/protected vars exposed Actual result: -------------- private/protected vars exposed on php version higher than 7.1 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 23:00:01 2025 UTC |
It seems the behavior was originally broken in PHP-7.0, when we introduced INIT_USER_CALL opcode. The same code without "namespace crm;" prints private/protected members in PHP-7.*, but not in PHP-5.*. Now, in PHP-7.1 the behavior of call_user_func() in namespace is consistent with behavior outside namespace (however, this was made unintendedly). We should fix this for both cases in PHP-7.0 and above (e.g. introduce ZEND_CALL_CALLBACK flag and disable call_user_func("internal_func",...) optimisation), or document the behavior change. @nikic, what do you think?IMHO: Both calls should output the same. I don't expect that the scope changes if i use call_user_func. var_dump(call_user_func('get_object_vars', $this)); var_dump(get_object_vars($this));