From: Robin Fernandes Date: Mon, 3 Mar 2008 15:07:04 +0000 (+0000) Subject: Remove inconsistent behaviour when a protected static prop is overridden by public... X-Git-Tag: BEFORE_NEW_PARAMETER_PARSE~714 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0455ccb80552a053e2130a9107da9cc2c80eac82;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 f8b380388d..093a441f87 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -2482,18 +2482,6 @@ static zend_bool do_inherit_property_access_check(HashTable *target_ht, zend_pro ht = &parent_ce->default_static_members; } if (zend_hash_find(ht, prot_name, prot_name_length+1, (void**)&prop) == SUCCESS) { - zval **new_prop; - if (zend_hash_find(&ce->default_static_members, 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) { - char *prop_name, *tmp; - zend_unmangle_property_name(child_info->name, child_info->name_length, &tmp, &prop_name); - - zend_error(E_COMPILE_ERROR, "Cannot change initial value of property static protected %s::$%s in class %s", - parent_ce->name, prop_name, ce->name); - } - } - Z_ADDREF_PP(prop); - zend_hash_update(&ce->default_static_members, child_info->name, child_info->name_length+1, (void**)prop, sizeof(zval*), NULL); zend_hash_del(&ce->default_static_members, prot_name, prot_name_length+1); } } else { 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