helly Mon Jul 10 00:13:50 2006 UTC Added files: /php-src/ext/reflection/tests bug37816.phpt
Modified files: /php-src/ext/reflection php_reflection.c Log: - Fix bug #37816 ReflectionProperty does not throw exception when accessing protected attribute http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/php_reflection.c?r1=1.241&r2=1.242&diff_format=u Index: php-src/ext/reflection/php_reflection.c diff -u php-src/ext/reflection/php_reflection.c:1.241 php-src/ext/reflection/php_reflection.c:1.242 --- php-src/ext/reflection/php_reflection.c:1.241 Sun Jul 9 23:28:59 2006 +++ php-src/ext/reflection/php_reflection.c Mon Jul 10 00:13:50 2006 @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_reflection.c,v 1.241 2006/07/09 23:28:59 helly Exp $ */ +/* $Id: php_reflection.c,v 1.242 2006/07/10 00:13:50 helly Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -3907,24 +3907,25 @@ { reflection_object *intern; property_reference *ref; - zval *object; + zval *object, name; zval **member= NULL; zend_uchar utype = UG(unicode)?IS_UNICODE:IS_STRING; METHOD_NOTSTATIC(reflection_property_ptr); GET_REFLECTION_OBJECT_PTR(ref); -#if MBO_0 if (!(ref->prop->flags & ZEND_ACC_PUBLIC)) { - _DO_THROW("Cannot access non-public member"); - /* Returns from this function */ + _default_get_entry(getThis(), "name", sizeof("name"), &name TSRMLS_CC); + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + "Cannot access non-public member %v::%v", intern->ce->name, Z_UNIVAL(name)); + zval_dtor(&name); + return; } -#endif if ((ref->prop->flags & ZEND_ACC_STATIC)) { zend_update_class_constants(intern->ce TSRMLS_CC); if (zend_u_hash_quick_find(CE_STATIC_MEMBERS(intern->ce), utype, ref->prop->name, ref->prop->name_length + 1, ref->prop->h, (void **) &member) == FAILURE) { - zend_error(E_ERROR, "Internal error: Could not find the property %v", ref->prop->name); + zend_error(E_ERROR, "Internal error: Could not find the property %v::%v", intern->ce->name, ref->prop->name); /* Bails out */ } } else { @@ -3932,7 +3933,7 @@ return; } if (zend_u_hash_quick_find(Z_OBJPROP_P(object), utype, ref->prop->name, ref->prop->name_length + 1, ref->prop->h, (void **) &member) == FAILURE) { - zend_error(E_ERROR, "Internal error: Could not find the property %v", ref->prop->name); + zend_error(E_ERROR, "Internal error: Could not find the property %v::%v", intern->ce->name, ref->prop->name); /* Bails out */ } } @@ -3950,7 +3951,7 @@ reflection_object *intern; property_reference *ref; zval **variable_ptr; - zval *object; + zval *object, name; zval *value; int setter_done = 0; zval *tmp; @@ -3961,8 +3962,11 @@ GET_REFLECTION_OBJECT_PTR(ref); if (!(ref->prop->flags & ZEND_ACC_PUBLIC)) { - _DO_THROW("Cannot access non-public member"); - /* Returns from this function */ + _default_get_entry(getThis(), "name", sizeof("name"), &name TSRMLS_CC); + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + "Cannot access non-public member %v::%v", intern->ce->name, Z_UNIVAL(name)); + zval_dtor(&name); + return; } if ((ref->prop->flags & ZEND_ACC_STATIC)) { @@ -3981,7 +3985,7 @@ } if (zend_u_hash_quick_find(prop_table, utype, ref->prop->name, ref->prop->name_length + 1, ref->prop->h, (void **) &variable_ptr) == FAILURE) { - zend_error(E_ERROR, "Internal error: Could not find the property %v", ref->prop->name); + zend_error(E_ERROR, "Internal error: Could not find the property %v::%v", intern->ce->name, ref->prop->name); /* Bails out */ } if (*variable_ptr == value) { @@ -4832,7 +4836,7 @@ php_info_print_table_start(); php_info_print_table_header(2, "Reflection", "enabled"); - php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 1.241 2006/07/09 23:28:59 helly Exp $"); + php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 1.242 2006/07/10 00:13:50 helly Exp $"); php_info_print_table_end(); } /* }}} */ http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/tests/bug37816.phpt?view=markup&rev=1.1 Index: php-src/ext/reflection/tests/bug37816.phpt +++ php-src/ext/reflection/tests/bug37816.phpt --TEST-- Bug #37816 (ReflectionProperty does not throw exception when accessing protected attribute) --FILE-- <?php class TestClass { protected $p = 2; } $o = new TestClass; $r = new ReflectionProperty($o, 'p'); try { $x = $r->getValue($o); } catch (Exception $e) { echo 'Caught: ' . $e->getMessage() . "\n"; } ?> ===DONE=== --EXPECTF-- Caught: Cannot access non-public member TestClass::p ===DONE=== -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php