Edit report at https://bugs.php.net/bug.php?id=65357&edit=1
ID: 65357
User updated 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: Bug
Package: Reflection related
PHP Version: 5.4.17
Block user comment: N
Private report: N
New Comment:
in the example the line should be:
return $analyse($this);
Previous Comments:
------------------------------------------------------------------------
[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