Doc #73715 [Opn]: Undocumented change in 7.0 of call_user_func + get_object_vars

From: Date: Thu, 15 Dec 2016 15:22:32 +0000
Subject: Doc #73715 [Opn]: Undocumented change in 7.0 of call_user_func + get_object_vars
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-14240@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73715&edit=1 ID: 73715 Updated by: bwoebi@php.net Reported by: love at sickpeople dot se Summary: Undocumented change in 7.0 of call_user_func + get_object_vars Status: Open Type: Documentation Problem Package: Documentation problem PHP Version: Irrelevant Block user comment: N Private report: N New Comment: @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 https://3v4l.org/kuV9o) 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) Previous Comments: ------------------------------------------------------------------------ [2016-12-11 16:04:58] cmb@php.net The behavioral change *might* have been introduced with commit de306e70[1] and *might* not even have been intentional. [1] <http://git.php.net/?p=php-src.git;a=commit;h=de306e70882dd7dd04ea952ef3c665304837c3be> ------------------------------------------------------------------------ [2016-12-11 01:09:51] 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 http://php.net/manual/en/migration70.incompatible.php http://php.net/manual/en/migration70.changed-functions.php ------------------------------------------------------------------------ [2016-12-11 01:05:44] love at sickpeople dot se Description: ------------ 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: http://php.net/manual/en/function.get-object-vars.php#113435 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 http://php.net/manual/en/migration71.incompatible.php or http://php.net/manual/en/migration71.changed-functions.php - 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: ---------------- https://3v4l.org/94ES3 - The result between PHP 5 and PHP 7 differs ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73715&edit=1

« previous php.doc.bugs (#14240) next »