com php-src: fix #72209 (ReflectionProperty::getValue() doesn't fail if object doesn't match type): NEWS ext/reflection/php_reflectio n.c
ext/reflection/tests/ReflectionProperty_getValue_er ror.phpt

From: Date: Sat, 14 May 2016 05:28:11 +0000
Subject: com php-src: fix #72209 (ReflectionProperty::getValue() doesn't fail if object doesn't match type): NEWS ext/reflection/php_reflectio n.c
ext/reflection/tests/ReflectionProperty_getValue_er ror.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-92122@lists.php.net to get a copy of this message
Commit: 3684d411721c3b5dc85be74c5317e4d6311ad021 Author: Joe Watkins <krakjoe@php.net> Sat, 14 May 2016 06:28:11 +0100 Parents: 49a7be069700efbb98dbb076bb0891c748c343f4 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3684d411721c3b5dc85be74c5317e4d6311ad021 Log: fix #72209 (ReflectionProperty::getValue() doesn't fail if object doesn't match type) Bugs: https://bugs.php.net/72209 Changed paths: M NEWS M ext/reflection/php_reflection.c M ext/reflection/tests/ReflectionProperty_getValue_error.phpt Diff: diff --git a/NEWS b/NEWS index 0138872..381fb18 100644 --- 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) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 38cfec6..13003ca 100644 --- a/ext/reflection/php_reflection.c +++ b/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) { diff --git a/ext/reflection/tests/ReflectionProperty_getValue_error.phpt b/ext/reflection/tests/ReflectionProperty_getValue_error.phpt index 62009d8..c9bf0b0 100644 --- a/ext/reflection/tests/ReflectionProperty_getValue_error.phpt +++ b/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

« previous php.cvs (#92122) next »