Doc #65357 [Com]: get_object_vars behavior changed unexpected after version upgrade from php 5.3

From: Date: Tue, 13 Aug 2013 11:07:29 +0000
Subject: Doc #65357 [Com]: get_object_vars behavior changed unexpected after version upgrade from php 5.3
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-10164@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65357&edit=1 ID: 65357 Comment by: phpbugreport at darkaura dot de Reported by: phpbugreport at darkaura dot de Summary: get_object_vars behavior changed unexpected after version upgrade from php 5.3 Status: Open Type: Documentation Problem Package: Reflection related PHP Version: 5.4.17 Block user comment: N Private report: N New Comment: Servus Johannes, I mildly disagree in this not beeing at least a reduction of features. There was an easy way to get only the publics of an object from inside that object (ask an object for its publics) that no longer exists. Now you have to use the full reflections of the object which is slower or instanciate "something" else that is a real class with a name that then calls get_object_vars instead of something that dont has a name. A other solution would be to have an additional parameter for get_object_vars() that is somehow telling the function what scope to use to analyse the object given. best reg4rds Previous Comments: ------------------------------------------------------------------------ [2013-07-30 11:14:27] johannes@php.net This is a effect of making $this available in closures. This example might be added to the documentation. ------------------------------------------------------------------------ [2013-07-30 09:43:21] phpbugreport at darkaura dot de in the example the line should be: return $analyse($this); ------------------------------------------------------------------------ [2013-07-30 09:40:34] phpbugreport at darkaura dot de Description: ------------ --- From manual page: http://www.php.net/function.get-object-vars --- get_object_vars exposes more than it should if you wrap it in a closure. Not only $this but every variable pointing to the object the closure is in is put in a state where the prototected and private variables can be read. Test script: --------------- <?php class Example { public $publicSetting = 'public'; protected $protectedSetting = 'protected'; private $privateSetting = 'private'; public function showEverything() { return get_object_vars($this); } public function showMyPublicsOnly() { $analyse = function($object) { return get_object_vars($object); }; return $analyse($object); } } $example = new Example(); Expected result: ---------------- $example->showMyPublicsOnly() //Outputs array('publicSetting' => 'public'); Actual result: -------------- //PHP 5.3 $example->showMyPublicsOnly() //Outputs array('publicSetting' => 'public'); //PHP 5.4 and up $example->showMyPublicsOnly() //Outputs array('publicSetting' => 'public', 'protectedSetting' => 'protected', 'privateSetting' => 'private'); This change is not mentioned on the manual page. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65357&edit=1

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