]> granicus.if.org Git - php/commitdiff
Tests show updating consts must happen once at runtime (revert optimization).
authorMarcus Boerger <helly@php.net>
Thu, 4 Sep 2003 16:00:01 +0000 (16:00 +0000)
committerMarcus Boerger <helly@php.net>
Thu, 4 Sep 2003 16:00:01 +0000 (16:00 +0000)
Add tests for static properties.

Zend/zend_API.c
Zend/zend_execute.c
Zend/zend_object_handlers.c
ext/reflection/tests/static_properties_002.phpt [new file with mode: 0755]
tests/classes/static_properties_001.phpt [new file with mode: 0755]

index e95be0838c7897d99c4dfe4d141e078d7e078d93..136f48a0222fa2edb141ebe7a3e65e8c474956ac 100644 (file)
@@ -700,6 +700,7 @@ ZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *class_type
 
        if (!class_type->constants_updated) {
                zend_hash_apply_with_argument(&class_type->default_properties, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
+               zend_hash_apply_with_argument(class_type->static_members, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
                class_type->constants_updated = 1;
        }
        
@@ -1683,8 +1684,6 @@ ZEND_API int zend_declare_property(zend_class_entry *ce, char *name, int name_le
                        default:
                                break;
                }
-       } else {
-               zval_update_constant(&property, (void *) 1 TSRMLS_CC);
        }
        switch (access_type & ZEND_ACC_PPP_MASK) {
                case ZEND_ACC_PRIVATE: {
index c7eccbf33b6cd3a8640d963136ae6abd085ec94f..52fc671729e89b93d576002ec177501cd66ba078 100644 (file)
@@ -722,6 +722,7 @@ static void zend_fetch_var_address(zend_op *opline, temp_variable *Ts, int type
                                FREE_OP(Ts, &opline->op1, free_op1);
                                break;
                        case ZEND_FETCH_STATIC:
+                               zval_update_constant(retval, (void*) 1 TSRMLS_CC);
                                break;
                }
        }
index 3892918bf598d25b7b8af6c9a2bd3c5e6432b2b1..30b02ad95dd839b7b68ff1754a3b27fda51542a9 100644 (file)
@@ -736,6 +736,7 @@ zval **zend_std_get_static_property(zend_class_entry *ce, char *property_name, i
                }
        }
        
+       zval_update_constant(retval, (void *) 1 TSRMLS_CC);
        return retval;
 }
 
diff --git a/ext/reflection/tests/static_properties_002.phpt b/ext/reflection/tests/static_properties_002.phpt
new file mode 100755 (executable)
index 0000000..d62d8ac
--- /dev/null
@@ -0,0 +1,62 @@
+--TEST--
+ZE2 Inheriting static properties
+--SKIPIF--
+<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
+--FILE--
+<?php
+
+class base {
+       static protected $prop = 2;
+       
+       static function show() {
+               echo __METHOD__ . '(' . self::$prop . ")\n";
+       }
+       
+       static function inc() {
+               base::$prop++;
+               echo __METHOD__ . "()\n";
+       }
+}
+
+class derived extends base {
+       static public $prop;
+       
+       static function show() {
+               echo __METHOD__ . '(' . self::$prop . ")\n";
+       }
+
+       static function inc() {
+               derived::$prop++;
+               echo __METHOD__ . "()\n";
+       }
+}
+
+base::show();
+derived::show();
+
+base::inc();
+
+base::show();
+derived::show();
+
+derived::inc();
+
+base::show();
+derived::show();
+
+$r = new reflection_class('derived');
+echo 'Number of properties: '. count($r->getStaticProperties()) . "\n";
+
+echo "Done\n";
+?>
+--EXPECTF--
+base::show(2)
+derived::show(2)
+base::inc()
+base::show(3)
+derived::show(3)
+derived::inc()
+base::show(4)
+derived::show(4)
+Number of properties: 1
+Done
diff --git a/tests/classes/static_properties_001.phpt b/tests/classes/static_properties_001.phpt
new file mode 100755 (executable)
index 0000000..1c34f68
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+ZE2 Initializing static properties to arrays
+--SKIPIF--
+<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
+--FILE--
+<?php
+
+class test {
+       static public $ar = array();
+}
+
+var_dump(test::$ar);
+
+test::$ar[] = 1;
+
+var_dump(test::$ar);
+
+echo "Done\n";
+?>
+--EXPECTF--
+array(0) {
+}
+array(1) {
+  [0]=>
+  int(1)
+}
+Done