From: Dmitry Stogov Date: Mon, 6 Jun 2005 07:51:19 +0000 (+0000) Subject: Fixed bug #33171 (foreach enumerates private fields declared in base classes) X-Git-Tag: php-5.0.5RC1~209 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3452a4d9cb592325047889343a3f8ce8bbf1b3d8;p=php Fixed bug #33171 (foreach enumerates private fields declared in base classes) --- diff --git a/NEWS b/NEWS index 56345ee8e7..e044c6b1a5 100644 --- 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 index 0000000000..27f5264bad --- /dev/null +++ b/Zend/tests/bug33171.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #33171 (foreach enumerates private fields declared in base classes) +--FILE-- + $val) + { + echo "$key => $val\n"; + } + } +}; + +$x = new B; +$x->go(); +?> +--EXPECT-- +c => B's c diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 6b1cde047d..cb3c865d14 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -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; }