cvs: ZendEngine2(PHP_5_0) / zend_compile.c zend_compile.h zend_object_handlers.c zend_reflection_api.c /tests bug29689.phpt
| From: | Stanislav Malyshev | Date: | Thu, 09 Jun 2005 16:59:58 +0000 |
| Subject: | cvs: ZendEngine2(PHP_5_0) / zend_compile.c zend_compile.h zend_object_handlers.c zend_reflection_api.c /tests bug29689.phpt | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-3782@lists.php.net to get a copy of this message | ||
stas Thu Jun 9 12:59:58 2005 EDT
Modified files: (Branch: PHP_5_0)
/ZendEngine2 zend_compile.c zend_compile.h zend_object_handlers.c
zend_reflection_api.c
/ZendEngine2/tests bug29689.phpt
Log:
fix #29689 and more private property problems
http://cvs.php.net/diff.php/ZendEngine2/zend_compile.c?r1=1.567.2.23&r2=1.567.2.24&ty=u Index: ZendEngine2/zend_compile.c diff -u ZendEngine2/zend_compile.c:1.567.2.23 ZendEngine2/zend_compile.c:1.567.2.24 --- ZendEngine2/zend_compile.c:1.567.2.23 Wed Jun 8 14:10:28 2005 +++ ZendEngine2/zend_compile.c Thu Jun 9 12:59:55 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.c,v 1.567.2.23 2005/06/08 18:10:28 dmitry Exp $ */ +/* $Id: zend_compile.c,v 1.567.2.24 2005/06/09 16:59:55 stas Exp $ */ #include <zend_language_parser.h> #include "zend.h" @@ -1860,9 +1860,18 @@ zend_property_info *child_info; zend_class_entry *parent_ce = ce->parent; - if (parent_info->flags & ZEND_ACC_PRIVATE) { + if (parent_info->flags & (ZEND_ACC_PRIVATE|ZEND_ACC_SHADOW)) { if (zend_hash_quick_find(&ce->properties_info, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void **) &child_info)==SUCCESS) { child_info->flags |= ZEND_ACC_CHANGED; + } else { + zend_hash_quick_update(&ce->properties_info, hash_key->arKey, hash_key->nKeyLength, hash_key->h, parent_info, sizeof(zend_property_info), (void **) &child_info); + if(ce->type & ZEND_INTERNAL_CLASS) { + zend_duplicate_property_info_internal(child_info); + } else { + zend_duplicate_property_info(child_info); + } + child_info->flags &= ~ZEND_ACC_PRIVATE; /* it's not private anymore */ + child_info->flags |= ZEND_ACC_SHADOW; /* but it's a shadow of private */ } return 0; /* don't copy access information to child */ } @@ -1874,6 +1883,11 @@ (child_info->flags & ZEND_ACC_STATIC) ? "static " : "non static ", ce->name, hash_key->arKey); } + + if(parent_info->flags & ZEND_ACC_CHANGED) { + child_info->flags |= ZEND_ACC_CHANGED; + } + if ((child_info->flags & ZEND_ACC_PPP_MASK) > (parent_info->flags & ZEND_ACC_PPP_MASK)) { zend_error(E_COMPILE_ERROR, "Access level to %s::$%s must be %s (as in class %s)%s", ce->name, hash_key->arKey, zend_visibility_string(parent_info->flags), parent_ce->name, (parent_info->flags&ZEND_ACC_PUBLIC) ? "" : " or weaker"); } else if (child_info->flags & ZEND_ACC_IMPLICIT_PUBLIC) { http://cvs.php.net/diff.php/ZendEngine2/zend_compile.h?r1=1.284.2.3&r2=1.284.2.4&ty=u Index: ZendEngine2/zend_compile.h diff -u ZendEngine2/zend_compile.h:1.284.2.3 ZendEngine2/zend_compile.h:1.284.2.4 --- ZendEngine2/zend_compile.h:1.284.2.3 Tue Jun 7 14:07:52 2005 +++ ZendEngine2/zend_compile.h Thu Jun 9 12:59:56 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.h,v 1.284.2.3 2005/06/07 18:07:52 dmitry Exp $ */ +/* $Id: zend_compile.h,v 1.284.2.4 2005/06/09 16:59:56 stas Exp $ */ #ifndef ZEND_COMPILE_H #define ZEND_COMPILE_H @@ -134,6 +134,9 @@ /* method flag (bc only), any method that has this flag can be used statically and non statically. */ #define ZEND_ACC_ALLOW_STATIC 0x10000 +/* shadow of parent's private method/property */ +#define ZEND_ACC_SHADOW 0x20000 + char *zend_visibility_string(zend_uint fn_flags); http://cvs.php.net/diff.php/ZendEngine2/zend_object_handlers.c?r1=1.101.2.15&r2=1.101.2.16&ty=u Index: ZendEngine2/zend_object_handlers.c diff -u ZendEngine2/zend_object_handlers.c:1.101.2.15 ZendEngine2/zend_object_handlers.c:1.101.2.16 --- ZendEngine2/zend_object_handlers.c:1.101.2.15 Wed Jun 8 04:05:27 2005 +++ ZendEngine2/zend_object_handlers.c Thu Jun 9 12:59:56 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_object_handlers.c,v 1.101.2.15 2005/06/08 08:05:27 dmitry Exp $ */ +/* $Id: zend_object_handlers.c,v 1.101.2.16 2005/06/09 16:59:56 stas Exp $ */ #include "zend.h" #include "zend_globals.h" @@ -206,22 +206,27 @@ } h = zend_get_hash_value(Z_STRVAL_P(member), Z_STRLEN_P(member) + 1); if (zend_hash_quick_find(&zobj->ce->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, h, (void **) &property_info)==SUCCESS) { - if (zend_verify_property_access(property_info, zobj->ce TSRMLS_CC)) { - if (property_info->flags & ZEND_ACC_CHANGED - && !(property_info->flags & ZEND_ACC_PRIVATE)) { - /* We still need to make sure that we're not in a context - * where the right property is a different 'statically linked' private - * continue checking below... - */ - } else { - if (!silent && (property_info->flags & ZEND_ACC_STATIC)) { - zend_error(E_STRICT, "Accessing static property %s::$%s as non static", zobj->ce->name, Z_STRVAL_P(member)); + if(property_info->flags & ZEND_ACC_SHADOW) { + /* if it's a shadow - go to access it's private */ + property_info = NULL; + } else { + if (zend_verify_property_access(property_info, zobj->ce TSRMLS_CC)) { + if (property_info->flags & ZEND_ACC_CHANGED + && !(property_info->flags & ZEND_ACC_PRIVATE)) { + /* We still need to make sure that we're not in a context + * where the right property is a different 'statically linked' private + * continue checking below... + */ + } else { + if (!silent && (property_info->flags & ZEND_ACC_STATIC)) { + zend_error(E_STRICT, "Accessing static property %s::$%s as non static", zobj->ce->name, Z_STRVAL_P(member)); + } + return property_info; } - return property_info; + } else { + /* Try to look in the scope instead */ + denied_access = 1; } - } else { - /* Try to look in the scope instead */ - denied_access = 1; } } if (EG(scope) != zobj->ce @@ -229,6 +234,9 @@ && EG(scope) && zend_hash_quick_find(&EG(scope)->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, h, (void **) &scope_property_info)==SUCCESS && scope_property_info->flags & ZEND_ACC_PRIVATE) { + if (!silent && (scope_property_info->flags & ZEND_ACC_STATIC)) { + zend_error(E_STRICT, "Accessing static property %s::$%s as non static", EG(scope)->name, Z_STRVAL_P(member)); + } return scope_property_info; } else if (property_info) { if (denied_access) { @@ -809,7 +817,7 @@ zend_property_info *property_info; zend_property_info std_property_info; - if (zend_hash_find(&ce->properties_info, property_name, property_name_len+1, (void **) &property_info)==FAILURE) { + if (zend_hash_find(&ce->properties_info, property_name, property_name_len+1, (void **) &property_info)==FAILURE || (property_info->flags & ZEND_ACC_SHADOW)) { std_property_info.flags = ZEND_ACC_PUBLIC; std_property_info.name = property_name; std_property_info.name_length = property_name_len; @@ -817,7 +825,7 @@ property_info = &std_property_info; } -#if 1&&DEBUG_OBJECT_HANDLERS +#if DEBUG_OBJECT_HANDLERS zend_printf("Access type for %s::%s is %s\n", ce->name, property_name, zend_visibility_string(property_info->flags)); #endif http://cvs.php.net/diff.php/ZendEngine2/zend_reflection_api.c?r1=1.111.2.20&r2=1.111.2.21&ty=u Index: ZendEngine2/zend_reflection_api.c diff -u ZendEngine2/zend_reflection_api.c:1.111.2.20 ZendEngine2/zend_reflection_api.c:1.111.2.21 --- ZendEngine2/zend_reflection_api.c:1.111.2.20 Mon Apr 25 01:14:46 2005 +++ ZendEngine2/zend_reflection_api.c Thu Jun 9 12:59:56 2005 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_reflection_api.c,v 1.111.2.20 2005/04/25 05:14:46 sebastian Exp $ */ +/* $Id: zend_reflection_api.c,v 1.111.2.21 2005/06/09 16:59:56 stas Exp $ */ #include "zend.h" #include "zend_API.h" #include "zend_exceptions.h" @@ -257,7 +257,7 @@ /* {{{ _class_string */ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *indent TSRMLS_DC) { - int count, count_static_props = 0, count_static_funcs = 0; + int count, count_static_props = 0, count_static_funcs = 0, count_shadow_props = 0; string sub_indent; string_init(&sub_indent); @@ -349,7 +349,9 @@ zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop, &pos) == SUCCESS) { - if (prop->flags & ZEND_ACC_STATIC) { + if(prop->flags & ZEND_ACC_SHADOW) { + count_shadow_props++; + } else if (prop->flags & ZEND_ACC_STATIC) { count_static_props++; } zend_hash_move_forward_ex(&ce->properties_info, &pos); @@ -365,9 +367,10 @@ zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop, &pos) == SUCCESS) { - if (prop->flags & ZEND_ACC_STATIC) { + if ((prop->flags & ZEND_ACC_STATIC) && !(prop->flags & ZEND_ACC_SHADOW)) { _property_string(str, prop, NULL, sub_indent.string TSRMLS_CC); } + zend_hash_move_forward_ex(&ce->properties_info, &pos); } } @@ -415,7 +418,7 @@ /* Default/Implicit properties */ if (&ce->properties_info) { - count = zend_hash_num_elements(&ce->properties_info) - count_static_props; + count = zend_hash_num_elements(&ce->properties_info) - count_static_props - count_shadow_props; string_printf(str, "\n%s - Properties [%d] {\n", indent, count); if (count > 0) { HashPosition pos; @@ -424,7 +427,7 @@ zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop, &pos) == SUCCESS) { - if (!(prop->flags & ZEND_ACC_STATIC)) { + if (!(prop->flags & (ZEND_ACC_STATIC|ZEND_ACC_SHADOW))) { _property_string(str, prop, NULL, sub_indent.string TSRMLS_CC); } zend_hash_move_forward_ex(&ce->properties_info, &pos); @@ -2403,7 +2406,7 @@ } GET_REFLECTION_OBJECT_PTR(ce); - if (zend_hash_find(&ce->properties_info, name, name_len + 1, (void**) &property_info) == SUCCESS) { + if (zend_hash_find(&ce->properties_info, name, name_len + 1, (void**) &property_info) == SUCCESS && (property_info->flags & ZEND_ACC_SHADOW) == 0) { reflection_property_factory(ce, property_info, return_value TSRMLS_CC); } else { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, @@ -2421,6 +2424,10 @@ zval *retval = va_arg(args, zval*); long filter = va_arg(args, long); + if (pptr->flags & ZEND_ACC_SHADOW) { + return 0; + } + if (pptr->flags & filter) { TSRMLS_FETCH(); ALLOC_ZVAL(property); @@ -2904,7 +2911,7 @@ /* returns out of this function */ } - if (zend_hash_find(&ce->properties_info, name_str, name_len + 1, (void **) &property_info) == FAILURE) { + if (zend_hash_find(&ce->properties_info, name_str, name_len + 1, (void **) &property_info) == FAILURE || (property_info->flags | ZEND_ACC_SHADOW)) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Property %s::$%s does not exist", ce->name, name_str); return; http://cvs.php.net/diff.php/ZendEngine2/tests/bug29689.phpt?r1=1.1.2.1&r2=1.1.2.2&ty=u Index: ZendEngine2/tests/bug29689.phpt diff -u ZendEngine2/tests/bug29689.phpt:1.1.2.1 ZendEngine2/tests/bug29689.phpt:1.1.2.2 --- ZendEngine2/tests/bug29689.phpt:1.1.2.1 Wed May 18 10:51:08 2005 +++ ZendEngine2/tests/bug29689.phpt Thu Jun 9 12:59:57 2005 @@ -1,57 +1,62 @@ ---TEST-- -Bug #29689 (default value of protected member overrides default value of private) ---FILE-- -<?php -class foo { - private $foo = 'foo'; - - function printFoo() - { - echo __CLASS__, ': ', $this->foo, "\n"; - } -} - -class bar extends foo { - protected $foo = 'bar'; - - function printFoo() - { - parent::printFoo(); - echo __CLASS__, ': ', $this->foo, "\n"; - } -} - -class baz extends bar { - protected $foo = 'baz'; -} - -class bar2 extends foo { - function printFoo() - { - parent::printFoo(); - echo __CLASS__, ': ', $this->foo, "\n"; - } -} - -class baz2 extends bar2 { - protected $foo = 'baz2'; -} - -$bar = new bar; -$bar->printFoo(); -echo "---\n"; -$baz = new baz(); -$baz->printFoo(); -echo "---\n"; -$baz = new baz2(); -$baz->printFoo(); -?> ---EXPECT-- -foo: foo -bar: bar ---- -foo: foo -bar: baz ---- -foo: foo -bar2: baz2 +--TEST-- +Bug #29689 (default value of protected member overrides default value of private) +--FILE-- +<?php +class foo { + private $foo = 'foo'; + private $foo2 = 'foo2'; + + function printFoo() + { + echo __CLASS__, ': ', $this->foo, " ", $this->foo2, "\n"; + } +} + +class bar extends foo { + protected $foo = 'bar'; + + function printFoo() + { + parent::printFoo(); + echo __CLASS__, ': ', $this->foo, " ", $this->foo2, "\n"; + } +} + +class baz extends bar { + protected $foo = 'baz'; + protected $foo2 = 'baz2'; +} + +class bar2 extends foo { + function printFoo() + { + parent::printFoo(); + echo __CLASS__, ': ', $this->foo, " ", $this->foo2, "\n"; + } +} + +class baz2 extends bar2 { + protected $foo = 'baz2'; + protected $foo2 = 'baz22'; +} + +$bar = new bar; +$bar->printFoo(); +echo "---baz--\n"; +$baz = new baz(); +$baz->printFoo(); +echo "---baz2--\n"; +$baz = new baz2(); +$baz->printFoo(); +?> +--EXPECTF-- +foo: foo foo2 +bar: bar +Notice: Undefined property: bar::$foo2 in %s on line %d + +---baz-- +foo: foo foo2 +bar: baz baz2 +---baz2-- +foo: foo foo2 +bar2: baz2 baz22
http://cvs.php.net/diff.php/ZendEngine2/zend_compile.c?r1=1.567.2.23&r2=1.567.2.24&ty=u Index: ZendEngine2/zend_compile.c diff -u ZendEngine2/zend_compile.c:1.567.2.23 ZendEngine2/zend_compile.c:1.567.2.24 --- ZendEngine2/zend_compile.c:1.567.2.23 Wed Jun 8 14:10:28 2005 +++ ZendEngine2/zend_compile.c Thu Jun 9 12:59:55 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.c,v 1.567.2.23 2005/06/08 18:10:28 dmitry Exp $ */ +/* $Id: zend_compile.c,v 1.567.2.24 2005/06/09 16:59:55 stas Exp $ */ #include <zend_language_parser.h> #include "zend.h" @@ -1860,9 +1860,18 @@ zend_property_info *child_info; zend_class_entry *parent_ce = ce->parent; - if (parent_info->flags & ZEND_ACC_PRIVATE) { + if (parent_info->flags & (ZEND_ACC_PRIVATE|ZEND_ACC_SHADOW)) { if (zend_hash_quick_find(&ce->properties_info, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void **) &child_info)==SUCCESS) { child_info->flags |= ZEND_ACC_CHANGED; + } else { + zend_hash_quick_update(&ce->properties_info, hash_key->arKey, hash_key->nKeyLength, hash_key->h, parent_info, sizeof(zend_property_info), (void **) &child_info); + if(ce->type & ZEND_INTERNAL_CLASS) { + zend_duplicate_property_info_internal(child_info); + } else { + zend_duplicate_property_info(child_info); + } + child_info->flags &= ~ZEND_ACC_PRIVATE; /* it's not private anymore */ + child_info->flags |= ZEND_ACC_SHADOW; /* but it's a shadow of private */ } return 0; /* don't copy access information to child */ } @@ -1874,6 +1883,11 @@ (child_info->flags & ZEND_ACC_STATIC) ? "static " : "non static ", ce->name, hash_key->arKey); } + + if(parent_info->flags & ZEND_ACC_CHANGED) { + child_info->flags |= ZEND_ACC_CHANGED; + } + if ((child_info->flags & ZEND_ACC_PPP_MASK) > (parent_info->flags & ZEND_ACC_PPP_MASK)) { zend_error(E_COMPILE_ERROR, "Access level to %s::$%s must be %s (as in class %s)%s", ce->name, hash_key->arKey, zend_visibility_string(parent_info->flags), parent_ce->name, (parent_info->flags&ZEND_ACC_PUBLIC) ? "" : " or weaker"); } else if (child_info->flags & ZEND_ACC_IMPLICIT_PUBLIC) { http://cvs.php.net/diff.php/ZendEngine2/zend_compile.h?r1=1.284.2.3&r2=1.284.2.4&ty=u Index: ZendEngine2/zend_compile.h diff -u ZendEngine2/zend_compile.h:1.284.2.3 ZendEngine2/zend_compile.h:1.284.2.4 --- ZendEngine2/zend_compile.h:1.284.2.3 Tue Jun 7 14:07:52 2005 +++ ZendEngine2/zend_compile.h Thu Jun 9 12:59:56 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.h,v 1.284.2.3 2005/06/07 18:07:52 dmitry Exp $ */ +/* $Id: zend_compile.h,v 1.284.2.4 2005/06/09 16:59:56 stas Exp $ */ #ifndef ZEND_COMPILE_H #define ZEND_COMPILE_H @@ -134,6 +134,9 @@ /* method flag (bc only), any method that has this flag can be used statically and non statically. */ #define ZEND_ACC_ALLOW_STATIC 0x10000 +/* shadow of parent's private method/property */ +#define ZEND_ACC_SHADOW 0x20000 + char *zend_visibility_string(zend_uint fn_flags); http://cvs.php.net/diff.php/ZendEngine2/zend_object_handlers.c?r1=1.101.2.15&r2=1.101.2.16&ty=u Index: ZendEngine2/zend_object_handlers.c diff -u ZendEngine2/zend_object_handlers.c:1.101.2.15 ZendEngine2/zend_object_handlers.c:1.101.2.16 --- ZendEngine2/zend_object_handlers.c:1.101.2.15 Wed Jun 8 04:05:27 2005 +++ ZendEngine2/zend_object_handlers.c Thu Jun 9 12:59:56 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_object_handlers.c,v 1.101.2.15 2005/06/08 08:05:27 dmitry Exp $ */ +/* $Id: zend_object_handlers.c,v 1.101.2.16 2005/06/09 16:59:56 stas Exp $ */ #include "zend.h" #include "zend_globals.h" @@ -206,22 +206,27 @@ } h = zend_get_hash_value(Z_STRVAL_P(member), Z_STRLEN_P(member) + 1); if (zend_hash_quick_find(&zobj->ce->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, h, (void **) &property_info)==SUCCESS) { - if (zend_verify_property_access(property_info, zobj->ce TSRMLS_CC)) { - if (property_info->flags & ZEND_ACC_CHANGED - && !(property_info->flags & ZEND_ACC_PRIVATE)) { - /* We still need to make sure that we're not in a context - * where the right property is a different 'statically linked' private - * continue checking below... - */ - } else { - if (!silent && (property_info->flags & ZEND_ACC_STATIC)) { - zend_error(E_STRICT, "Accessing static property %s::$%s as non static", zobj->ce->name, Z_STRVAL_P(member)); + if(property_info->flags & ZEND_ACC_SHADOW) { + /* if it's a shadow - go to access it's private */ + property_info = NULL; + } else { + if (zend_verify_property_access(property_info, zobj->ce TSRMLS_CC)) { + if (property_info->flags & ZEND_ACC_CHANGED + && !(property_info->flags & ZEND_ACC_PRIVATE)) { + /* We still need to make sure that we're not in a context + * where the right property is a different 'statically linked' private + * continue checking below... + */ + } else { + if (!silent && (property_info->flags & ZEND_ACC_STATIC)) { + zend_error(E_STRICT, "Accessing static property %s::$%s as non static", zobj->ce->name, Z_STRVAL_P(member)); + } + return property_info; } - return property_info; + } else { + /* Try to look in the scope instead */ + denied_access = 1; } - } else { - /* Try to look in the scope instead */ - denied_access = 1; } } if (EG(scope) != zobj->ce @@ -229,6 +234,9 @@ && EG(scope) && zend_hash_quick_find(&EG(scope)->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, h, (void **) &scope_property_info)==SUCCESS && scope_property_info->flags & ZEND_ACC_PRIVATE) { + if (!silent && (scope_property_info->flags & ZEND_ACC_STATIC)) { + zend_error(E_STRICT, "Accessing static property %s::$%s as non static", EG(scope)->name, Z_STRVAL_P(member)); + } return scope_property_info; } else if (property_info) { if (denied_access) { @@ -809,7 +817,7 @@ zend_property_info *property_info; zend_property_info std_property_info; - if (zend_hash_find(&ce->properties_info, property_name, property_name_len+1, (void **) &property_info)==FAILURE) { + if (zend_hash_find(&ce->properties_info, property_name, property_name_len+1, (void **) &property_info)==FAILURE || (property_info->flags & ZEND_ACC_SHADOW)) { std_property_info.flags = ZEND_ACC_PUBLIC; std_property_info.name = property_name; std_property_info.name_length = property_name_len; @@ -817,7 +825,7 @@ property_info = &std_property_info; } -#if 1&&DEBUG_OBJECT_HANDLERS +#if DEBUG_OBJECT_HANDLERS zend_printf("Access type for %s::%s is %s\n", ce->name, property_name, zend_visibility_string(property_info->flags)); #endif http://cvs.php.net/diff.php/ZendEngine2/zend_reflection_api.c?r1=1.111.2.20&r2=1.111.2.21&ty=u Index: ZendEngine2/zend_reflection_api.c diff -u ZendEngine2/zend_reflection_api.c:1.111.2.20 ZendEngine2/zend_reflection_api.c:1.111.2.21 --- ZendEngine2/zend_reflection_api.c:1.111.2.20 Mon Apr 25 01:14:46 2005 +++ ZendEngine2/zend_reflection_api.c Thu Jun 9 12:59:56 2005 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_reflection_api.c,v 1.111.2.20 2005/04/25 05:14:46 sebastian Exp $ */ +/* $Id: zend_reflection_api.c,v 1.111.2.21 2005/06/09 16:59:56 stas Exp $ */ #include "zend.h" #include "zend_API.h" #include "zend_exceptions.h" @@ -257,7 +257,7 @@ /* {{{ _class_string */ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *indent TSRMLS_DC) { - int count, count_static_props = 0, count_static_funcs = 0; + int count, count_static_props = 0, count_static_funcs = 0, count_shadow_props = 0; string sub_indent; string_init(&sub_indent); @@ -349,7 +349,9 @@ zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop, &pos) == SUCCESS) { - if (prop->flags & ZEND_ACC_STATIC) { + if(prop->flags & ZEND_ACC_SHADOW) { + count_shadow_props++; + } else if (prop->flags & ZEND_ACC_STATIC) { count_static_props++; } zend_hash_move_forward_ex(&ce->properties_info, &pos); @@ -365,9 +367,10 @@ zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop, &pos) == SUCCESS) { - if (prop->flags & ZEND_ACC_STATIC) { + if ((prop->flags & ZEND_ACC_STATIC) && !(prop->flags & ZEND_ACC_SHADOW)) { _property_string(str, prop, NULL, sub_indent.string TSRMLS_CC); } + zend_hash_move_forward_ex(&ce->properties_info, &pos); } } @@ -415,7 +418,7 @@ /* Default/Implicit properties */ if (&ce->properties_info) { - count = zend_hash_num_elements(&ce->properties_info) - count_static_props; + count = zend_hash_num_elements(&ce->properties_info) - count_static_props - count_shadow_props; string_printf(str, "\n%s - Properties [%d] {\n", indent, count); if (count > 0) { HashPosition pos; @@ -424,7 +427,7 @@ zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop, &pos) == SUCCESS) { - if (!(prop->flags & ZEND_ACC_STATIC)) { + if (!(prop->flags & (ZEND_ACC_STATIC|ZEND_ACC_SHADOW))) { _property_string(str, prop, NULL, sub_indent.string TSRMLS_CC); } zend_hash_move_forward_ex(&ce->properties_info, &pos); @@ -2403,7 +2406,7 @@ } GET_REFLECTION_OBJECT_PTR(ce); - if (zend_hash_find(&ce->properties_info, name, name_len + 1, (void**) &property_info) == SUCCESS) { + if (zend_hash_find(&ce->properties_info, name, name_len + 1, (void**) &property_info) == SUCCESS && (property_info->flags & ZEND_ACC_SHADOW) == 0) { reflection_property_factory(ce, property_info, return_value TSRMLS_CC); } else { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, @@ -2421,6 +2424,10 @@ zval *retval = va_arg(args, zval*); long filter = va_arg(args, long); + if (pptr->flags & ZEND_ACC_SHADOW) { + return 0; + } + if (pptr->flags & filter) { TSRMLS_FETCH(); ALLOC_ZVAL(property); @@ -2904,7 +2911,7 @@ /* returns out of this function */ } - if (zend_hash_find(&ce->properties_info, name_str, name_len + 1, (void **) &property_info) == FAILURE) { + if (zend_hash_find(&ce->properties_info, name_str, name_len + 1, (void **) &property_info) == FAILURE || (property_info->flags | ZEND_ACC_SHADOW)) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Property %s::$%s does not exist", ce->name, name_str); return; http://cvs.php.net/diff.php/ZendEngine2/tests/bug29689.phpt?r1=1.1.2.1&r2=1.1.2.2&ty=u Index: ZendEngine2/tests/bug29689.phpt diff -u ZendEngine2/tests/bug29689.phpt:1.1.2.1 ZendEngine2/tests/bug29689.phpt:1.1.2.2 --- ZendEngine2/tests/bug29689.phpt:1.1.2.1 Wed May 18 10:51:08 2005 +++ ZendEngine2/tests/bug29689.phpt Thu Jun 9 12:59:57 2005 @@ -1,57 +1,62 @@ ---TEST-- -Bug #29689 (default value of protected member overrides default value of private) ---FILE-- -<?php -class foo { - private $foo = 'foo'; - - function printFoo() - { - echo __CLASS__, ': ', $this->foo, "\n"; - } -} - -class bar extends foo { - protected $foo = 'bar'; - - function printFoo() - { - parent::printFoo(); - echo __CLASS__, ': ', $this->foo, "\n"; - } -} - -class baz extends bar { - protected $foo = 'baz'; -} - -class bar2 extends foo { - function printFoo() - { - parent::printFoo(); - echo __CLASS__, ': ', $this->foo, "\n"; - } -} - -class baz2 extends bar2 { - protected $foo = 'baz2'; -} - -$bar = new bar; -$bar->printFoo(); -echo "---\n"; -$baz = new baz(); -$baz->printFoo(); -echo "---\n"; -$baz = new baz2(); -$baz->printFoo(); -?> ---EXPECT-- -foo: foo -bar: bar ---- -foo: foo -bar: baz ---- -foo: foo -bar2: baz2 +--TEST-- +Bug #29689 (default value of protected member overrides default value of private) +--FILE-- +<?php +class foo { + private $foo = 'foo'; + private $foo2 = 'foo2'; + + function printFoo() + { + echo __CLASS__, ': ', $this->foo, " ", $this->foo2, "\n"; + } +} + +class bar extends foo { + protected $foo = 'bar'; + + function printFoo() + { + parent::printFoo(); + echo __CLASS__, ': ', $this->foo, " ", $this->foo2, "\n"; + } +} + +class baz extends bar { + protected $foo = 'baz'; + protected $foo2 = 'baz2'; +} + +class bar2 extends foo { + function printFoo() + { + parent::printFoo(); + echo __CLASS__, ': ', $this->foo, " ", $this->foo2, "\n"; + } +} + +class baz2 extends bar2 { + protected $foo = 'baz2'; + protected $foo2 = 'baz22'; +} + +$bar = new bar; +$bar->printFoo(); +echo "---baz--\n"; +$baz = new baz(); +$baz->printFoo(); +echo "---baz2--\n"; +$baz = new baz2(); +$baz->printFoo(); +?> +--EXPECTF-- +foo: foo foo2 +bar: bar +Notice: Undefined property: bar::$foo2 in %s on line %d + +---baz-- +foo: foo foo2 +bar: baz baz2 +---baz2-- +foo: foo foo2 +bar2: baz2 baz22