]> granicus.if.org Git - php/commitdiff
- Support static $var = 0; style initialization of static class
authorAndi Gutmans <andi@php.net>
Mon, 26 Nov 2001 18:05:01 +0000 (18:05 +0000)
committerAndi Gutmans <andi@php.net>
Mon, 26 Nov 2001 18:05:01 +0000 (18:05 +0000)
- members. For example:
- class foo {
- static $my_static = 5;
-
- }
-
- print foo::$my_static;

Zend/zend_compile.c
Zend/zend_compile.h
Zend/zend_language_parser.y

index 41b43b156bcea088c550df74d1dcfcf7a4fbfec5..c1596ac3efe8782fdac2cc747be61c03a2ccee2a 100644 (file)
@@ -1800,7 +1800,7 @@ void zend_do_end_class_declaration(znode *class_token TSRMLS_DC)
 }
 
 
-void zend_do_declare_property(znode *var_name, znode *value TSRMLS_DC)
+void zend_do_declare_property(znode *var_name, znode *value, int declaration_type TSRMLS_DC)
 {
        if (value) {
                zval *property;
@@ -1808,7 +1808,11 @@ void zend_do_declare_property(znode *var_name, znode *value TSRMLS_DC)
                ALLOC_ZVAL(property);
 
                *property = value->u.constant;
-               zend_hash_update(&CG(active_class_entry)->default_properties, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, &property, sizeof(zval *), NULL);
+               if (declaration_type == T_VAR) {
+                       zend_hash_update(&CG(active_class_entry)->default_properties, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, &property, sizeof(zval *), NULL);
+               } else {
+                       zend_hash_update(&CG(active_class_entry)->static_members, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, &property, sizeof(zval *), NULL);
+               }
        }
        FREE_PNODE(var_name);
 }
index e133a01941697e64c6300fc0666938396dd42564..27266f4b7edde9fbeb0e350c161e07d30010cd3e 100644 (file)
@@ -304,7 +304,7 @@ void zend_do_default_before_statement(znode *case_list, znode *default_token TSR
 
 void zend_do_begin_class_declaration(znode *class_token, znode *class_name, znode *parent_class_name TSRMLS_DC);
 void zend_do_end_class_declaration(znode *class_token TSRMLS_DC);
-void zend_do_declare_property(znode *var_name, znode *value TSRMLS_DC);
+void zend_do_declare_property(znode *var_name, znode *value, int declaration_type TSRMLS_DC);
 
 void zend_do_fetch_property(znode *result, znode *object, znode *property TSRMLS_DC);
 
index e772889bb6c4b41203c47edb67c02f4aad240b31..31bfa6b4e0f38ff0b0d2e84404d8c38ece4e2dec 100644 (file)
@@ -386,7 +386,7 @@ class_statement_list:
 
 
 class_statement:
-               T_VAR class_variable_decleration ';'
+               class_variable_decleration ';'
        |       T_FUNCTION { $1.u.opline_num = CG(zend_lineno); } is_reference T_STRING { zend_do_begin_function_declaration(&$1, &$4, 1, $3.op_type TSRMLS_CC); } '(' 
                        parameter_list ')' '{' inner_statement_list '}' { zend_do_end_function_declaration(&$1 TSRMLS_CC); }
        |       T_OLD_FUNCTION { $1.u.opline_num = CG(zend_lineno); } is_reference T_STRING { zend_do_begin_function_declaration(&$1, &$4, 1, $3.op_type TSRMLS_CC); }
@@ -400,12 +400,16 @@ is_reference:
        |       '&'                     { $$.op_type = ZEND_RETURN_REF; }
 
 class_variable_decleration:
-               class_variable_decleration ',' T_VARIABLE                                       { zend_do_declare_property(&$3, NULL TSRMLS_CC); }
-       |       class_variable_decleration ',' T_VARIABLE '=' static_scalar     { zend_do_declare_property(&$3, &$5 TSRMLS_CC); }
-       |       T_VARIABLE                                              { zend_do_declare_property(&$1, NULL TSRMLS_CC); }
-       |       T_VARIABLE '=' static_scalar    { zend_do_declare_property(&$1, &$3 TSRMLS_CC); }
+               class_variable_decleration ',' T_VARIABLE                                       { zend_do_declare_property(&$3, NULL, $1.op_type TSRMLS_CC); }
+       |       class_variable_decleration ',' T_VARIABLE '=' static_scalar     { zend_do_declare_property(&$3, &$5, $1.op_type TSRMLS_CC); }
+       |       class_decleration_type T_VARIABLE                                               { $$ = $1; zend_do_declare_property(&$2, NULL, $1.op_type TSRMLS_CC); }
+       |       class_decleration_type T_VARIABLE '=' static_scalar     { $$ = $1; zend_do_declare_property(&$2, &$4, $1.op_type TSRMLS_CC); }
 ;
 
+class_decleration_type:
+               T_VAR           { $$.op_type = T_VAR; }
+       |       T_STATIC        { $$.op_type = T_STATIC; }
+;
 
 echo_expr_list:        
        |       echo_expr_list ',' expr { zend_do_echo(&$3 TSRMLS_CC); }