Bug #65357 [NEW]: get_object_vars behavior changed unexpected after version upgrade from php 5.3
From: phpbugreport at darkaura dot de
Operating system:
PHP version: 5.4.17
Package: Reflection related
Bug Type: Bug
Bug description:get_object_vars behavior changed unexpected after version upgrade from php 5.3
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 bug report at https://bugs.php.net/bug.php?id=65357&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65357&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65357&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65357&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65357&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65357&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65357&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65357&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65357&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65357&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65357&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=65357&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=65357&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65357&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65357&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65357&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65357&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65357&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65357&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65357&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65357&r=mysqlcfg
Thread (3 messages)
- phpbugreport at darkaura dot de