]> granicus.if.org Git - php/commitdiff
Remove inconsistent behaviour when a protected static prop is overridden by public...
authorRobin Fernandes <robinf@php.net>
Mon, 3 Mar 2008 15:07:04 +0000 (15:07 +0000)
committerRobin Fernandes <robinf@php.net>
Mon, 3 Mar 2008 15:07:04 +0000 (15:07 +0000)
Zend/tests/errmsg_024.phpt
Zend/tests/lsb_019.phpt [new file with mode: 0644]
Zend/tests/lsb_020.phpt [new file with mode: 0644]
Zend/zend_compile.c
ext/reflection/tests/static_properties_002.phpt
tests/classes/property_override_protectedStatic_publicStatic.phpt

index d8d06cbce17a9bbfa9d6fb1fccd019b23e325853..011e6fdea9a73d6fd0af47f60456bb09bf6d6702 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-errmsg: cannot change initial value of property
+No more errmsg: can now change initial value of property
 --FILE--
 <?php
 
@@ -14,4 +14,4 @@ class test extends test1 {
 echo "Done\n";
 ?>
 --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 (file)
index 0000000..f0d2bc2
--- /dev/null
@@ -0,0 +1,48 @@
+--TEST--
+Test LSB of properties and methods declared as protected and overridden as public. 
+--FILE--
+<?php
+class TestClass {
+       protected static $staticVar;
+
+       protected static function staticFunction() {
+               return 'TestClassFunction';
+       }
+       
+       public static function testStaticVar() {
+               TestClass::$staticVar = 'TestClassStatic';
+               ChildClass1::$staticVar = 'ChildClassStatic';
+               return static::$staticVar;
+       }
+
+       public static function testStaticFunction() {
+               return static::staticFunction();
+       }
+}
+
+class ChildClass1 extends TestClass {
+       public static $staticVar;
+
+       public static function staticFunction() {
+               return 'ChildClassFunction';
+       }
+}
+
+class ChildClass2 extends TestClass {}
+
+echo TestClass::testStaticVar() . "\n";
+echo TestClass::testStaticFunction() . "\n";
+
+echo ChildClass1::testStaticVar() . "\n";
+echo ChildClass1::testStaticFunction() . "\n";
+
+echo ChildClass2::testStaticVar() . "\n";
+echo ChildClass2::testStaticFunction() . "\n";
+?>
+--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 (file)
index 0000000..f328b01
--- /dev/null
@@ -0,0 +1,48 @@
+--TEST--
+Test LSB of properties and methods declared as public and overridden as public. 
+--FILE--
+<?php
+class TestClass {
+       public static $staticVar;
+
+       public static function staticFunction() {
+               return 'TestClassFunction';
+       }
+       
+       public static function testStaticVar() {
+               TestClass::$staticVar = 'TestClassStatic';
+               ChildClass1::$staticVar = 'ChildClassStatic';
+               return static::$staticVar;
+       }
+
+       public static function testStaticFunction() {
+               return static::staticFunction();
+       }
+}
+
+class ChildClass1 extends TestClass {
+       public static $staticVar;
+
+       public static function staticFunction() {
+               return 'ChildClassFunction';
+       }
+}
+
+class ChildClass2 extends TestClass {}
+
+echo TestClass::testStaticVar() . "\n";
+echo TestClass::testStaticFunction() . "\n";
+
+echo ChildClass1::testStaticVar() . "\n";
+echo ChildClass1::testStaticFunction() . "\n";
+
+echo ChildClass2::testStaticVar() . "\n";
+echo ChildClass2::testStaticFunction() . "\n";
+?>
+--EXPECTF--
+TestClassStatic
+TestClassFunction
+ChildClassStatic
+ChildClassFunction
+TestClassStatic
+TestClassFunction
\ No newline at end of file
index f8b380388dffc55720c6e769010a8221f22ff785..093a441f87a801b0a5ab86be26956b4b2feca26d 100644 (file)
@@ -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 {
index 051b9fb10e6ba896c79e2a46bb1ae2b4fea77252..0713af40c44b39bd0d898da2c451163afb5a5f11 100755 (executable)
@@ -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
index 7e1955dd99c22e42b8d6d57f0d703d2db9ab2fa7..e437c5f30f3d93a50e74311f31e9cdc8af1230e8 100644 (file)
@@ -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