Bug #72174 [Com]: ReflectionProperty#getValue() causes __isset call
| From: | ocramius at gmail dot com | Date: | Tue, 10 May 2016 14:14:01 +0000 |
| Subject: | Bug #72174 [Com]: ReflectionProperty#getValue() causes __isset call | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200992@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72174&edit=1
ID: 72174
Comment by: ocramius at gmail dot com
Reported by: ocramius at gmail dot com
Summary: ReflectionProperty#getValue() causes __isset call
Status: Closed
Type: Bug
Package: Reflection related
PHP Version: 7.0.6
Block user comment: N
Private report: N
New Comment:
Looks good from here! Related tests seem to pass on 7.0.7-DEV
:beer:
Previous Comments:
------------------------------------------------------------------------
[2016-05-10 10:18:29] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a1ed4ab3caf33b59742897b43462d033864bb490
Log: Fixed bug #72174
------------------------------------------------------------------------
[2016-05-07 19:00:31] ocramius at gmail dot com
As per discussion with NikiC and bwoebi in http://chat.stackoverflow.com/transcript/message/30402977#30402977
There has been an ever-living bug in
ReflectionProperty#getValue() that causes the
reflection property to be read (and return NULL) even when not set, and that without
causing a warning. That can be seen at https://3v4l.org/vdOjh
Code below as reference:
```php
<?php
class Foo
{
public $bar;
}
$instance = new Foo;
unset($instance->bar);
var_dump((new ReflectionProperty(Foo::class, 'bar'))->getValue($instance));
```
This code always returns NULL, but it should raise a NOTICE.
PHP 7.0.6 somehow mitigates the bug by doing an implicit isset() check internally, but
that changes behavior of ReflectionProperty#getValue() in such a way that it breaks
some userland existing code ( https://github.com/Ocramius/ProxyManager/issues/306
- possibly also other codebases) by causing __isset calls.
Making ReflectionProperty#getValue() trigger a notice when a property IS_UNDEF could
probably be a good solution.
------------------------------------------------------------------------
[2016-05-07 18:59:54] nikic@php.net
To summarize OTR discussion:
The issue is that ReflectionProperty::getValue() currently performs a "silenced read",
which is roughly equivalent to doing isset($obj->prop) ? $obj->prop : NULL. Prior to PHP 7.0.6
the isset($obj->prop) part did not result in a call to __isset() due to a bug in the magic method
implementation.
However, it can be be argued that ReflectionProperty::getValue() should not be performing a silenced
read in the first place. It should simply return the value of $obj->prop. If we make this change
then the behavior described in the bug report will go back to what it was. On the other hand, this
means that using ReflectionProperty::getValue() to read an undefined property will throw an
undefined property notice (currently suppressed: https://3v4l.org/vdOjh).
The current plan is to change ReflectionProperty::getValue() to perform the read without silencing.
------------------------------------------------------------------------
[2016-05-07 18:48:57] ocramius at gmail dot com
Bug seems to really only affect reflection access: https://3v4l.org/GY4NC
------------------------------------------------------------------------
[2016-05-07 18:27:36] ocramius at gmail dot com
Note: bug was discovered in builds of ProxyManager at https://travis-ci.org/Ocramius/ProxyManager/jobs/128480921#L384
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=72174
--
Edit this bug report at https://bugs.php.net/bug.php?id=72174&edit=1