]> granicus.if.org Git - php/commitdiff
Fix bug #24499
authorZeev Suraski <zeev@php.net>
Mon, 21 Jul 2003 12:13:16 +0000 (12:13 +0000)
committerZeev Suraski <zeev@php.net>
Mon, 21 Jul 2003 12:13:16 +0000 (12:13 +0000)
Zend/zend_object_handlers.c
tests/lang/bug24499.phpt [new file with mode: 0755]

index 78aa8af692ca87e369ba0daa674653b7cee39904..399f7bfab87911f7e33f0ad2ad4f687bd1a9d2f8 100644 (file)
@@ -178,13 +178,25 @@ inline int zend_verify_property_access(zend_property_info *property_info, zend_c
        return 0;
 }
 
+static inline zend_bool is_derived_class(zend_class_entry *child_class, zend_class_entry *parent_class)
+{
+       child_class = child_class->parent;
+       while (child_class) {
+               if (child_class == parent_class) {
+                       return 1;
+               }
+               child_class = child_class->parent;
+       }
+
+       return 0;
+}
+
 static inline zend_property_info *zend_get_property_info(zend_object *zobj, zval *member TSRMLS_DC)
 {
        zend_property_info *property_info = NULL;
        zend_property_info *scope_property_info;
        zend_bool denied_access = 0;
 
-
        ulong h = zend_get_hash_value(Z_STRVAL_P(member), Z_STRLEN_P(member)+1);
        if (zend_hash_quick_find(&zobj->ce->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, h, (void **) &property_info)==SUCCESS) {
                if (zend_verify_property_access(property_info, zobj->ce TSRMLS_CC)) {
@@ -203,6 +215,7 @@ static inline zend_property_info *zend_get_property_info(zend_object *zobj, zval
                }
        }
        if (EG(scope) != zobj->ce
+               && is_derived_class(zobj->ce, EG(scope))
                && EG(scope)
                && zend_hash_quick_find(&EG(scope)->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, h, (void **) &scope_property_info)==SUCCESS
                && scope_property_info->flags & ZEND_ACC_PRIVATE) {
diff --git a/tests/lang/bug24499.phpt b/tests/lang/bug24499.phpt
new file mode 100755 (executable)
index 0000000..6ce56db
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+Bug #24499 (bogus handling of a public property as a private one)
+--FILE--
+<?php
+class Id {
+        private $id="priv";
+
+        public function tester($obj)
+        {
+                       $obj->id = "bar";
+        }
+}
+
+$id = new Id();
+@$obj->foo = "bar";
+$id->tester($obj);
+print_r($obj);
+?>
+--EXPECT--
+stdClass Object
+(
+    [foo] => bar
+    [id] => bar
+)