From cd88e646fd69ab1242cd331ca025048daca312b7 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 6 Jun 2005 07:52:08 +0000 Subject: [PATCH] Fixed bug #33171 (foreach enumerates private fields declared in base classes) --- Zend/tests/bug33171.phpt | 27 +++++++++++++++++++++++++++ Zend/zend_object_handlers.c | 11 ++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100755 Zend/tests/bug33171.phpt 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 3b68573ccd..83e80428d6 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -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; } -- 2.50.1