]> granicus.if.org Git - php/commitdiff
fix #72209 (ReflectionProperty::getValue() doesn't fail if object doesn't match type)
authorJoe Watkins <krakjoe@php.net>
Sat, 14 May 2016 05:28:11 +0000 (06:28 +0100)
committerJoe Watkins <krakjoe@php.net>
Sat, 14 May 2016 05:28:11 +0000 (06:28 +0100)
NEWS
ext/reflection/php_reflection.c
ext/reflection/tests/ReflectionProperty_getValue_error.phpt

diff --git a/NEWS b/NEWS
index 01388721ff01303406d21bdde3ae80ca54a2ff1f..381fb181ebc52db0170e120194a48b6a377d0799 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -58,6 +58,9 @@ PHP                                                                        NEWS
     messages). (Yasuo)
   . Implemented FR #48532 (Allow pg_fetch_all() to index numerically). (Yasuo)
 
+- Reflection:
+  . Fix #72209 (ReflectionProperty::getValue() doesn't fail if object doesn't match type). (Joe)
+
 - Session:
   . Improved fix for bug #68063 (Empty session IDs do still start sessions).
     (Yasuo)
index 38cfec6aa91310f424dc41c721823be87b7a7c02..13003cae845b769a2497168433e8c74c80ef1221 100644 (file)
@@ -5648,6 +5648,11 @@ ZEND_METHOD(reflection_property, getValue)
                        return;
                }
 
+               if (!instanceof_function(Z_OBJCE_P(object), ref->ce)) {
+                       _DO_THROW("Given object is not an instance of the class this property was declared in");
+                       /* Returns from this function */
+               }
+
                zend_unmangle_property_name_ex(ref->prop.name, &class_name, &prop_name, &prop_name_len);
                member_p = zend_read_property(ref->ce, object, prop_name, prop_name_len, 0, &rv);
                if (member_p != &rv) {
index 62009d8bb9ed18f9db28ceb42809dfc4a074c0d8..c9bf0b0f25d2ed2a34c19cc6a50a8ee059b759b0 100644 (file)
@@ -15,7 +15,7 @@ class AnotherClass {
 }
 
 $instance = new TestClass();
-$instanceWithNoProperties = new AnotherClass();
+$invalidInstance = new AnotherClass();
 $propInfo = new ReflectionProperty('TestClass', 'pub2');
 
 echo "Too few args:\n";
@@ -45,9 +45,9 @@ catch(Exception $exc) {
     echo $exc->getMessage();
 }
 
-echo "\n\nInstance without property:\n";
+echo "\n\nInvalid instance:\n";
 $propInfo = new ReflectionProperty('TestClass', 'pub2');
-var_dump($propInfo->getValue($instanceWithNoProperties));
+var_dump($propInfo->getValue($invalidInstance));
 
 ?>
 --EXPECTF--
@@ -77,7 +77,10 @@ string(15) "static property"
 Protected property:
 Cannot access non-public member TestClass::prot
 
-Instance without property:
+Invalid instance:
 
-Notice: Undefined property: AnotherClass::$pub2 in %s on line %d
-NULL
+Fatal error: Uncaught ReflectionException: Given object is not an instance of the class this property was declared in in %s:47
+Stack trace:
+#0 %s(47): ReflectionProperty->getValue(Object(AnotherClass))
+#1 {main}
+  thrown in %s on line 47