]> 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:51:19 +0000 (07:51 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 6 Jun 2005 07:51:19 +0000 (07:51 +0000)
NEWS
Zend/tests/bug33171.phpt [new file with mode: 0755]
Zend/zend_object_handlers.c

diff --git a/NEWS b/NEWS
index 56345ee8e7d4215979734ca09fa1c74c1e6c6124..e044c6b1a5c06a5c76866244e4b419a899e3ac29 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,8 @@ PHP                                                                        NEWS
 - Fixed bug #33200 (preg_replace(): magic_quotes_sybase=On makes 'e' modifier
   misbehave). (Jani)
 - Fixed bug #33185 (--enable-session=shared does not build). (Jani)
+- Fixed bug #33171 (foreach enumerates private fields declared in base
+  classes). (Dmitry)
 - Fixed bug #33164 (Soap extension incorrectly detects HTTP/1.1). (Ilia)
 - Fixed bug #33116 (crash when assigning class name to global variable in
   __autoload). (Dmitry)
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 6b1cde047df809338ec31e652864ea71bfa4484c..cb3c865d14f72cd99d360dac19c7923d2a9d090e 100644 (file)
@@ -260,9 +260,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;
 }