]> granicus.if.org Git - php/commitdiff
- Fix bug #37212 (Access to protected property of common base class)
authorMarcus Boerger <helly@php.net>
Sat, 27 May 2006 02:12:43 +0000 (02:12 +0000)
committerMarcus Boerger <helly@php.net>
Sat, 27 May 2006 02:12:43 +0000 (02:12 +0000)
  By adding "zend_class_entry *ce" to struct zend_property_info;
# Besides closing the bug this patch allows to optimize a bunch of
# property handling optimizations. I need to find out what all can be
# optimized. All other tests relevant to class handling still PASS.

Zend/tests/bug37212.phpt [new file with mode: 0755]
Zend/zend_API.c
Zend/zend_compile.h
Zend/zend_object_handlers.c

diff --git a/Zend/tests/bug37212.phpt b/Zend/tests/bug37212.phpt
new file mode 100755 (executable)
index 0000000..5e326ed
--- /dev/null
@@ -0,0 +1,69 @@
+--TEST--
+Bug #3721 (Access to protected property of common base class)
+--FILE--
+<?php
+
+class A
+{
+    protected $value;
+
+    public function __construct($val)
+    {
+        $this->value = $val;
+    }
+
+    protected function getValue()
+    {
+        return $this->value;
+    }
+}
+
+class B extends A
+{
+    public function copyValue($obj)
+    {
+        $this->value = $obj->getValue();
+        $this->value = $obj->value; // value defined in common base class
+    }
+}
+class C extends A {}
+
+$B = new B("B");
+var_dump($B);
+$C = new C("C");
+var_dump($C);
+
+$B->copyValue($C);
+
+var_dump($B);
+
+?>
+===DONE===
+--EXPECTF--
+object(B)#%d (1) {
+  ["value":protected]=>
+  string(1) "B"
+}
+object(C)#%d (1) {
+  ["value":protected]=>
+  string(1) "C"
+}
+object(B)#%d (1) {
+  ["value":protected]=>
+  string(1) "C"
+}
+===DONE===
+--UEXPECTF--
+object(B)#%d (1) {
+  [u"value":protected]=>
+  unicode(1) "B"
+}
+object(C)#%d (1) {
+  [u"value":protected]=>
+  unicode(1) "C"
+}
+object(B)#%d (1) {
+  [u"value":protected]=>
+  unicode(1) "C"
+}
+===DONE===
index 93927e10b8d3756020ab69065f1b444519e14418..5b1d3d7377d58d932ae4096d139e8f9ff21fedf4 100644 (file)
@@ -3028,6 +3028,8 @@ ZEND_API int zend_u_declare_property_ex(zend_class_entry *ce, zend_uchar type, z
 
        property_info.doc_comment = doc_comment;
        property_info.doc_comment_len = doc_comment_len;
+       
+       property_info.ce = ce;
 
        zend_u_hash_update(&ce->properties_info, type, name, name_length + 1, &property_info, sizeof(zend_property_info), NULL);
 
index 852dc684af0c297c2793800590494323f911c626..b8e4a965609d5b3fa3e1fb50d019dfec3e7bce50 100644 (file)
@@ -153,6 +153,7 @@ typedef struct _zend_property_info {
        ulong h;
        char *doc_comment;
        int doc_comment_len;
+       zend_class_entry *ce;
 } zend_property_info;
 
 
index f3323131fe30706309182b74246aa7a9626c31e7..266e23817d4d36bde80e20fe06e72a94b601cf4f 100644 (file)
@@ -150,7 +150,7 @@ static int zend_verify_property_access(zend_property_info *property_info, zend_c
                case ZEND_ACC_PUBLIC:
                        return 1;
                case ZEND_ACC_PROTECTED:
-                       return zend_check_protected(ce, EG(scope));
+                       return zend_check_protected(property_info->ce, EG(scope));
                case ZEND_ACC_PRIVATE:
                        if (ce==EG(scope) && EG(scope)) {
                                return 1;
@@ -239,6 +239,7 @@ ZEND_API struct _zend_property_info *zend_get_property_info(zend_class_entry *ce
                EG(std_property_info).name = Z_UNIVAL_P(member);
                EG(std_property_info).name_length = Z_UNILEN_P(member);
                EG(std_property_info).h = h;
+               EG(std_property_info).ce = ce;;
                property_info = &EG(std_property_info);
        }
        return property_info;
@@ -866,6 +867,7 @@ ZEND_API zval **zend_std_get_static_property(zend_class_entry *ce, zend_uchar ty
                std_property_info.name = property_name;
                std_property_info.name_length = property_name_len;
                std_property_info.h = zend_u_get_hash_value(UG(unicode)?IS_UNICODE:IS_STRING, std_property_info.name, std_property_info.name_length+1);
+               std_property_info.ce = ce;
                property_info = &std_property_info;
        }