Bug #62694 [Opn->Ver]: Obtaining the value of inexistent dynamic properties should not be allowed
| From: | cmb@php.net | Date: | Wed, 05 Sep 2018 14:22:03 +0000 |
| Subject: | Bug #62694 [Opn->Ver]: Obtaining the value of inexistent dynamic properties should not be allowed | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-216893@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62694&edit=1
ID: 62694
Updated by: cmb@php.net
Reported by: cataphract@php.net
Summary: Obtaining the value of inexistent dynamic properties
should not be allowed
-Status: Open
+Status: Verified
Type: Bug
Package: Reflection related
Operating System: Irrelevant
PHP Version: *
Block user comment: N
Private report: N
New Comment:
> Not fixed in all versions.
This issue does not appear to have been fixed at all. @cataphract
claims an exception should be thrown in this case (and I agree),
but only an E_NOTICE is issued.
It seems we would have to check whether the property is actually
defined before trying to get its value (something like
undef-dynamic-throw).
Previous Comments:
------------------------------------------------------------------------
[2018-09-05 14:21:33] cmb@php.net
The following patch has been added/updated:
Patch Name: undef-dynamic-throw
Revision: 1536157293
URL: https://bugs.php.net/patch-display.php?bug=62694&patch=undef-dynamic-throw&revision=1536157293
------------------------------------------------------------------------
[2014-07-15 11:31:51] yohgaki@php.net
Not fixed in all versions.
http://3v4l.org/PHAvK
------------------------------------------------------------------------
[2012-07-30 11:35:20] cataphract@php.net
Description:
------------
The reflection extension does not allow obtaining ReflectionProperty objects for non existent
properties, much less fetch their non existent value. However, this can be bypassed by creating a
dynamic ReflectionProperty in another object.
Test script:
---------------
<?php
class A {}
$a = new A;
$a->foo = "dynamic property";
$ro = new ReflectionObject($a);
$prop = $ro->getProperty('foo');
try {
var_dump($prop->getValue($a));
var_dump($prop->getValue(new A));
} catch (ReflectionException $ex) {
echo "Caught!\n";
try {
var_dump($prop->getValue(new A));
} catch (ReflectionException $ex) {
var_dump($ex->getMessage());
}
}
Expected result:
----------------
string(16) "dynamic property"
Caught!
string(49) "Dynamic property does not exist in given instance"
Actual result:
--------------
string(16) "dynamic property"
NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62694&edit=1