helly           Mon Jul 10 00:18:53 2006 UTC

  Added files:                 (Branch: PHP_5_2)
    /php-src/ext/reflection/tests       bug37816.phpt 

  Modified files:              
    /php-src    NEWS 
    /php-src/ext/reflection     php_reflection.c 
  Log:
  - MFH Fixed bug #37816 (ReflectionProperty does not throw exception when 
accessing protected attribute)
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.109&r2=1.2027.2.547.2.110&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.109 php-src/NEWS:1.2027.2.547.2.110
--- php-src/NEWS:1.2027.2.547.2.109     Sun Jul  9 22:45:32 2006
+++ php-src/NEWS        Mon Jul 10 00:18:53 2006
@@ -91,6 +91,8 @@
 - 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)
http://cvs.php.net/viewvc.cgi/php-src/ext/reflection/php_reflection.c?r1=1.164.2.33.2.12&r2=1.164.2.33.2.13&diff_format=u
Index: php-src/ext/reflection/php_reflection.c
diff -u php-src/ext/reflection/php_reflection.c:1.164.2.33.2.12 
php-src/ext/reflection/php_reflection.c:1.164.2.33.2.13
--- php-src/ext/reflection/php_reflection.c:1.164.2.33.2.12     Sun Jul  9 
23:30:19 2006
+++ php-src/ext/reflection/php_reflection.c     Mon Jul 10 00:18:53 2006
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_reflection.c,v 1.164.2.33.2.12 2006/07/09 23:30:19 helly Exp $ */
+/* $Id: php_reflection.c,v 1.164.2.33.2.13 2006/07/10 00:18:53 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -3838,23 +3838,24 @@
 {
        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 @@
                        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 @@
        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 @@
        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 @@
        }
 
        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) {
@@ -4764,7 +4768,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.164.2.33.2.12 2006/07/09 23:30:19 helly Exp $");
+       php_info_print_table_row(2, "Version", "$Id: php_reflection.c,v 
1.164.2.33.2.13 2006/07/10 00:18:53 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

Reply via email to