From: Robin Fernandes Date: Mon, 3 Mar 2008 14:24:11 +0000 (+0000) Subject: Remove inconsistent behaviour when a protected static prop is overridden by public... X-Git-Tag: RELEASE_2_0_0a1~269 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0188a097cc084c063b4a355b8ab9beb0dff9e5aa;p=php Remove inconsistent behaviour when a protected static prop is overridden by public static prop (details: http://turl.ca/phhhf ). --- diff --git a/Zend/tests/errmsg_024.phpt b/Zend/tests/errmsg_024.phpt index d8d06cbce1..011e6fdea9 100644 --- a/Zend/tests/errmsg_024.phpt +++ b/Zend/tests/errmsg_024.phpt @@ -1,5 +1,5 @@ --TEST-- -errmsg: cannot change initial value of property +No more errmsg: can now change initial value of property --FILE-- --EXPECTF-- -Fatal error: Cannot change initial value of property static protected test1::$var in class test in %s on line %d +Done diff --git a/Zend/tests/lsb_019.phpt b/Zend/tests/lsb_019.phpt new file mode 100644 index 0000000000..f0d2bc28c8 --- /dev/null +++ b/Zend/tests/lsb_019.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test LSB of properties and methods declared as protected and overridden as public. +--FILE-- + +--EXPECTF-- +TestClassStatic +TestClassFunction +ChildClassStatic +ChildClassFunction +TestClassStatic +TestClassFunction \ No newline at end of file diff --git a/Zend/tests/lsb_020.phpt b/Zend/tests/lsb_020.phpt new file mode 100644 index 0000000000..f328b01774 --- /dev/null +++ b/Zend/tests/lsb_020.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test LSB of properties and methods declared as public and overridden as public. +--FILE-- + +--EXPECTF-- +TestClassStatic +TestClassFunction +ChildClassStatic +ChildClassFunction +TestClassStatic +TestClassFunction \ No newline at end of file diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index c58bfa4315..b97f2cd54d 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -2696,18 +2696,6 @@ static zend_bool do_inherit_property_access_check(HashTable *target_ht, zend_pro ht = &parent_ce->default_static_members; } if (zend_u_hash_find(ht, utype, prot_name, prot_name_length+1, (void**)&prop) == SUCCESS) { - zval **new_prop; - if (zend_u_hash_find(&ce->default_static_members, utype, child_info->name, child_info->name_length+1, (void**)&new_prop) == SUCCESS) { - if (Z_TYPE_PP(new_prop) != IS_NULL && Z_TYPE_PP(prop) != IS_NULL) { - zstr prop_name, tmp; - - zend_u_unmangle_property_name(utype, child_info->name, child_info->name_length, &tmp, &prop_name); - zend_error(E_COMPILE_ERROR, "Cannot change initial value of property static protected %v::$%v in class %v", - parent_ce->name, prop_name, ce->name); - } - } - Z_ADDREF_PP(prop); - zend_u_hash_update(&ce->default_static_members, utype, child_info->name, child_info->name_length+1, (void**)prop, sizeof(zval*), NULL); zend_u_hash_del(&ce->default_static_members, utype, prot_name, prot_name_length+1); } } else { @@ -5674,3 +5662,4 @@ ZEND_API size_t zend_u_dirname(UChar *path, size_t len) * indent-tabs-mode: t * End: */ + diff --git a/ext/reflection/tests/static_properties_002.phpt b/ext/reflection/tests/static_properties_002.phpt index 051b9fb10e..0713af40c4 100755 --- a/ext/reflection/tests/static_properties_002.phpt +++ b/ext/reflection/tests/static_properties_002.phpt @@ -19,7 +19,7 @@ class base { } class derived extends base { - static public $prop; + static public $prop = 2; static function show() { echo __METHOD__ . '(' . self::$prop . ")\n"; @@ -54,9 +54,9 @@ base::show(2) derived::show(2) base::inc() base::show(3) -derived::show(3) +derived::show(2) derived::inc() -base::show(4) -derived::show(4) +base::show(3) +derived::show(3) Number of properties: 1 -Done +Done \ No newline at end of file diff --git a/tests/classes/property_override_protectedStatic_publicStatic.phpt b/tests/classes/property_override_protectedStatic_publicStatic.phpt index 7e1955dd99..e437c5f30f 100644 --- a/tests/classes/property_override_protectedStatic_publicStatic.phpt +++ b/tests/classes/property_override_protectedStatic_publicStatic.phpt @@ -27,5 +27,7 @@ Redeclare inherited protected static property as public static. B::showB(); ?> --EXPECTF-- +A::p (static) +A::p (static) +B::p (static) -Fatal error: Cannot change initial value of property static protected A::$p in class B in %s on line 18