]> granicus.if.org Git - php/commitdiff
Fixed bug #33171 (foreach enumerates private fields declared in base classes)
authorDmitry Stogov <dmitry@php.net>
Mon, 6 Jun 2005 07:52:08 +0000 (07:52 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 6 Jun 2005 07:52:08 +0000 (07:52 +0000)
Zend/tests/bug33171.phpt [new file with mode: 0755]
Zend/zend_object_handlers.c

diff --git a/Zend/tests/bug33171.phpt b/Zend/tests/bug33171.phpt
new file mode 100755 (executable)
index 0000000..27f5264
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+Bug #33171 (foreach enumerates private fields declared in base classes)
+--FILE--
+<?php
+class A
+{
+       private $c = "A's c";
+}
+
+class B extends A
+{
+       private $c = "B's c";
+               
+       public function go()
+       {
+               foreach ($this as $key => $val)
+               {
+                       echo "$key => $val\n";
+               }
+       }
+};
+
+$x = new B;
+$x->go();
+?>
+--EXPECT--
+c => B's c
index 3b68573ccd3ea46df7e3b0cd08b8454ac25b1228..83e80428d6990122a4194f6ce3030eb39ffd2c6e 100644 (file)
@@ -214,9 +214,14 @@ ZEND_API int zend_check_property_access(zend_object *zobj, char *prop_info_name
        if (!property_info) {
                return FAILURE;
        }
-       if (prop_info_name[0] == '\0' && prop_info_name[1] != '*' && !(property_info->flags & ZEND_ACC_PRIVATE)) {
-               /* we we're looking for a private prop but found a non private one of the same name */
-               return FAILURE;
+       if (prop_info_name[0] == '\0' && prop_info_name[1] != '*') {
+               if (!(property_info->flags & ZEND_ACC_PRIVATE)) {
+                       /* we we're looking for a private prop but found a non private one of the same name */
+                       return FAILURE;
+               } else if (strcmp(prop_info_name+1, property_info->name+1)) {
+                       /* we we're looking for a private prop but found a private one of the same name but another class */
+                       return FAILURE;
+               }
        }
        return zend_verify_property_access(property_info, zobj->ce TSRMLS_CC) ? SUCCESS : FAILURE;
 }