]> granicus.if.org Git - php/commitdiff
- MFH Fixed bug #37816 (ReflectionProperty does not throw exception when accessing...
authorMarcus Boerger <helly@php.net>
Mon, 10 Jul 2006 00:18:53 +0000 (00:18 +0000)
committerMarcus Boerger <helly@php.net>
Mon, 10 Jul 2006 00:18:53 +0000 (00:18 +0000)
NEWS
ext/reflection/php_reflection.c
ext/reflection/tests/bug37816.phpt [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index ae0aea4b7c467e3234e6608773a4f285283301e3..6a7ca088a3acc962f8190c85ad1eee26062ec0f8 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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)
index a223889a683200c9ed3fa13019f591fe0f20c71f..de1b6435e93ebf90cccbceb4ad0f761e47f36751 100644 (file)
@@ -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 (executable)
index 0000000..18a4904
--- /dev/null
@@ -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===