Browse Source

fix #72209 (ReflectionProperty::getValue() doesn't fail if object doesn't match type)

pull/1906/head
Joe Watkins 10 years ago
parent
commit
3684d41172
  1. 3
      NEWS
  2. 5
      ext/reflection/php_reflection.c
  3. 15
      ext/reflection/tests/ReflectionProperty_getValue_error.phpt

3
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)

5
ext/reflection/php_reflection.c

@ -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) {

15
ext/reflection/tests/ReflectionProperty_getValue_error.phpt

@ -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
Loading…
Cancel
Save