diff options
author | Marcus Boerger <helly@php.net> | 2006-07-10 00:18:53 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2006-07-10 00:18:53 +0000 |
commit | 71efa5b435f032b3a88204d8771b4f83869bec26 (patch) | |
tree | edc336dfa37e2e1df967a7a7c7390be036db2783 | |
parent | c5ff44688a6ce84c09c80236a7e460913219eebe (diff) | |
download | php-git-71efa5b435f032b3a88204d8771b4f83869bec26.tar.gz |
- MFH Fixed bug #37816 (ReflectionProperty does not throw exception when accessing protected attribute)
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | ext/reflection/php_reflection.c | 26 | ||||
-rwxr-xr-x | ext/reflection/tests/bug37816.phpt | 28 |
3 files changed, 45 insertions, 11 deletions
@@ -91,6 +91,8 @@ PHP NEWS - Fixed bug #37864 (file_get_contents() leaks on empty file). (Hannes) - Fixed bug #37862 (Integer pointer comparison to numeric value). (bugs-php at thewrittenword dot com) +- Fixed bug #37816 (ReflectionProperty does not throw exception when accessing + protected attribute). (Marcus) - Fixed bug #37811 (define not using toString on objects). (Marcus) - Fixed bug #37807 (segmentation fault during SOAP schema import). (Tony) - Fixed bug #37806 (weird behavior of object type and comparison). (Marcus) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index a223889a68..de1b6435e9 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3838,23 +3838,24 @@ ZEND_METHOD(reflection_property, getValue) { reflection_object *intern; property_reference *ref; - zval *object; + zval *object, name; zval **member= NULL; 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 %s::%s", intern->ce->name, Z_STRVAL(name)); + zval_dtor(&name); + return; } -#endif if ((ref->prop->flags & ZEND_ACC_STATIC)) { zend_update_class_constants(intern->ce TSRMLS_CC); if (zend_hash_quick_find(CE_STATIC_MEMBERS(intern->ce), 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 %s", ref->prop->name); + zend_error(E_ERROR, "Internal error: Could not find the property %s::%s", intern->ce->name, ref->prop->name); /* Bails out */ } } else { @@ -3862,7 +3863,7 @@ ZEND_METHOD(reflection_property, getValue) return; } if (zend_hash_quick_find(Z_OBJPROP_P(object), 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 %s", ref->prop->name); + zend_error(E_ERROR, "Internal error: Could not find the property %s::%s", intern->ce->name, ref->prop->name); /* Bails out */ } } @@ -3880,7 +3881,7 @@ ZEND_METHOD(reflection_property, setValue) reflection_object *intern; property_reference *ref; zval **variable_ptr; - zval *object; + zval *object, name; zval *value; int setter_done = 0; zval *tmp; @@ -3890,8 +3891,11 @@ ZEND_METHOD(reflection_property, setValue) 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 %s::%s", intern->ce->name, Z_STRVAL(name)); + zval_dtor(&name); + return; } if ((ref->prop->flags & ZEND_ACC_STATIC)) { @@ -3910,7 +3914,7 @@ ZEND_METHOD(reflection_property, setValue) } if (zend_hash_quick_find(prop_table, 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 %s", ref->prop->name); + zend_error(E_ERROR, "Internal error: Could not find the property %s::%s", intern->ce->name, ref->prop->name); /* Bails out */ } if (*variable_ptr == value) { diff --git a/ext/reflection/tests/bug37816.phpt b/ext/reflection/tests/bug37816.phpt new file mode 100755 index 0000000000..18a49046dc --- /dev/null +++ b/ext/reflection/tests/bug37816.phpt @@ -0,0 +1,28 @@ +--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=== |