diff options
author | Andi Gutmans <andi@php.net> | 2001-11-26 18:05:01 +0000 |
---|---|---|
committer | Andi Gutmans <andi@php.net> | 2001-11-26 18:05:01 +0000 |
commit | 7cd6ccc0ec9beca50034276fe349d2666ec945cb (patch) | |
tree | 1db942b96c8fbf5c508c7c5acec50a06f2f3078f /Zend | |
parent | 7c4daf11c04f90454adb67269b645e82fa47d8fd (diff) | |
download | php-git-7cd6ccc0ec9beca50034276fe349d2666ec945cb.tar.gz |
- Support static $var = 0; style initialization of static class
- members. For example:
- class foo {
- static $my_static = 5;
-
- }
-
- print foo::$my_static;
Diffstat (limited to 'Zend')
-rw-r--r-- | Zend/zend_compile.c | 8 | ||||
-rw-r--r-- | Zend/zend_compile.h | 2 | ||||
-rw-r--r-- | Zend/zend_language_parser.y | 14 |
3 files changed, 16 insertions, 8 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 41b43b156b..c1596ac3ef 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -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); } diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index e133a01941..27266f4b7e 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -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); diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index e772889bb6..31bfa6b4e0 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -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); } |