Bug #72174 [NEW]: ReflectionProperty#getValue() causes __isset call
| From: | ocramius at gmail dot com | Date: | Sat, 07 May 2016 18:24:17 +0000 |
| Subject: | Bug #72174 [NEW]: ReflectionProperty#getValue() causes __isset call | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-200938@lists.php.net to get a copy of this message | ||
From: ocramius at gmail dot com
Operating system:
PHP version: 7.0.6
Package: Reflection related
Bug Type: Bug
Bug description:ReflectionProperty#getValue() causes __isset call
Description:
------------
When using
ReflectionProperty#getValue($object) on a $object with an
unset() property and defined __isset and __get methods, the
__get method is called, while it should only use __get.
Note that this is a bug that affects only PHP 7.0.6, and isn't part of
7.0.5.
Test script:
---------------
<?php
class Foo
{
private $bar;
public function __construct()
{
unset($this->bar);
}
public function __isset($name)
{
var_dump(__METHOD__);
return true;
}
public function __get($name)
{
var_dump(__METHOD__);
return $name;
}
}
$instance = new Foo();
$reflectionBar = (new ReflectionProperty(Foo::class, 'bar'));
$reflectionBar->setAccessible(true);
$closureBar = (function (Foo $instance) {
return $instance->bar;
})->bindTo(null, Foo::class);
var_dump($reflectionBar->getValue($instance));
var_dump($closureBar($instance));
Expected result:
----------------
string(10) "Foo::__get"
string(3) "bar"
string(10) "Foo::__get"
string(3) "bar"
Actual result:
--------------
string(12) "Foo::__isset"
string(10) "Foo::__get"
string(3) "bar"
string(10) "Foo::__get"
string(3) "bar"
--
Edit bug report at https://bugs.php.net/bug.php?id=72174&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72174&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72174&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72174&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72174&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72174&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72174&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72174&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72174&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72174&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72174&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72174&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72174&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72174&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72174&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72174&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72174&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72174&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72174&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72174&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72174&r=mysqlcfg