]> granicus.if.org Git - php/commitdiff
$GLOBALS support
authorZeev Suraski <zeev@php.net>
Thu, 8 Apr 1999 20:21:36 +0000 (20:21 +0000)
committerZeev Suraski <zeev@php.net>
Thu, 8 Apr 1999 20:21:36 +0000 (20:21 +0000)
Zend/zend-parser.y
Zend/zend_compile.c
Zend/zend_compile.h
Zend/zend_execute.c
Zend/zend_opcode.c

index f5c51ff408e2bcbb2a4dee2b374e8634c026e3a6..0a20ef3435b214c18782d1e6df9502ac63f0bd87 100644 (file)
@@ -521,7 +521,7 @@ compound_variable:
 
 dim_list:
                dim_list ']' '[' dim_offset     { fetch_array_dim(&$$, &$1, &$4 CLS_CC); }
-       |       compound_variable  { do_begin_variable_parse(CLS_C); } '[' dim_offset           { fetch_array_begin(&$$, &$1, &$4 CLS_CC); }
+       |       compound_variable  { do_fetch_globals(&$1); do_begin_variable_parse(CLS_C); } '[' dim_offset            { fetch_array_begin(&$$, &$1, &$4 CLS_CC); }
 ;
 
 
@@ -604,10 +604,10 @@ encaps_list:
 
 
 encaps_var:
-               VARIABLE { do_begin_variable_parse(CLS_C); fetch_simple_variable(&$$, &$1, 1 CLS_CC); }
-       |       VARIABLE '[' encaps_var_offset ']'      { do_begin_variable_parse(CLS_C); fetch_array_begin(&$$, &$1, &$3 CLS_CC); }
+               VARIABLE { do_fetch_globals(&$1); do_begin_variable_parse(CLS_C); fetch_simple_variable(&$$, &$1, 1 CLS_CC); }
+       |       VARIABLE '[' encaps_var_offset ']'      { do_fetch_globals(&$1); do_begin_variable_parse(CLS_C); fetch_array_begin(&$$, &$1, &$3 CLS_CC); }
        |       VARIABLE ZEND_OBJECT_OPERATOR STRING { do_begin_variable_parse(CLS_C); fetch_simple_variable(&$2, &$1, 1 CLS_CC); do_fetch_property(&$$, &$2, &$3 CLS_CC); }
-       |       DOLLAR_OPEN_CURLY_BRACES expr '}' { do_begin_variable_parse(CLS_C); fetch_simple_variable(&$$, &$2, 1 CLS_CC); }
+       |       DOLLAR_OPEN_CURLY_BRACES expr '}' { do_begin_variable_parse(CLS_C);  fetch_simple_variable(&$$, &$2, 1 CLS_CC); }
        |       DOLLAR_OPEN_CURLY_BRACES STRING '[' expr ']' '}' { do_begin_variable_parse(CLS_C);  fetch_array_begin(&$$, &$2, &$4 CLS_CC); }
        |       T_CURLY_OPEN cvar '}' { $$ = $2; }
 ;
index 48b7d9aea1fb758aaafa50fa3a148a6a5cfe68d0..9f4dc4e079f1e2bcfa68897131c1204261389cd1 100644 (file)
@@ -154,6 +154,24 @@ void do_binary_assign_op(int op, znode *result, znode *op1, znode *op2 CLS_DC)
 }
 
 
+
+void do_fetch_globals(znode *varname)
+{
+       if (!CG(active_op_array)->initialized_globals
+               && varname->op_type == IS_CONST
+               && varname->u.constant.type == IS_STRING
+               && varname->u.constant.value.str.len == (sizeof("GLOBALS")-1)
+               && !memcmp(varname->u.constant.value.str.val, "GLOBALS", sizeof("GLOBALS")-1)) {
+               zend_op *opline = get_next_op(CG(active_op_array) CLS_CC);
+
+               opline->opcode = ZEND_INIT_GLOBALS;
+               SET_UNUSED(opline->op1);
+               SET_UNUSED(opline->op2);
+               CG(active_op_array)->initialized_globals = 1;
+       }
+}
+
+
 void fetch_simple_variable(znode *result, znode *varname, int bp CLS_DC)
 {
        int next_op_number = get_next_op_number(CG(active_op_array));
index 0eace155657ff97342106bf34a0bf21e3371c0dc..a6d7d834efd3c36d836f6aceee94cd1387559a6c 100644 (file)
@@ -91,6 +91,7 @@ struct _zend_op_array {
        zend_brk_cont_element *brk_cont_array;
        int last_brk_cont;
        int current_brk_cont;
+       unsigned char initialized_globals;
 
        /* static variables support */
        HashTable *static_variables;
@@ -195,6 +196,7 @@ void do_assign_ref(znode *result, znode *lvar, znode *rvar CLS_DC);
 void fetch_simple_variable(znode *result, znode *varname, int bp CLS_DC);
 void do_indirect_references(znode *result, znode *num_references, znode *variable CLS_DC);
 void do_fetch_global_or_static_variable(znode *varname, znode *static_assignment, int fetch_type CLS_DC);
+void do_fetch_globals(znode *varname);
 
 void fetch_array_begin(znode *result, znode *varname, znode *first_dim CLS_DC);
 void fetch_array_dim(znode *result, znode *parent, znode *dim CLS_DC);
@@ -450,11 +452,13 @@ int zendlex(znode *zendlval CLS_DC);
 
 #define ZEND_FETCH_DIM_TMP_VAR         89
 #define ZEND_FETCH_CONSTANT                    90
-                                                                       
-#define ZEND_EXT_STMT                          91
-#define ZEND_EXT_FCALL_BEGIN           92
-#define ZEND_EXT_FCALL_END                     93
-#define ZEND_EXT_NOP                           94
+
+#define ZEND_INIT_GLOBALS                      91
+
+#define ZEND_EXT_STMT                          92
+#define ZEND_EXT_FCALL_BEGIN           93
+#define ZEND_EXT_FCALL_END                     94
+#define ZEND_EXT_NOP                           95
 
 /* end of block */
 
index 8d6bbbbd91975335aeefd2ae7756a6bdecf41794..5683e93a8b60c5502d7bd75a1320e4aade6289e4 100644 (file)
@@ -1874,6 +1874,16 @@ send_by_ref:
                                        zend_llist_apply_with_argument(&zend_extensions, (void (*)(void *, void *)) zend_extension_fcall_end_handler, op_array);
                                }
                                break;
+                       case ZEND_INIT_GLOBALS: {
+                                       zval *globals = (zval *) emalloc(sizeof(zval));
+
+                                       globals->refcount=1;
+                                       globals->is_ref=1;
+                                       globals->type = IS_ARRAY;
+                                       globals->value.ht = &EG(symbol_table);
+                                       zend_hash_add(EG(active_symbol_table), "GLOBALS", sizeof("GLOBALS"), &globals, sizeof(zval *), NULL);
+                               }
+                               break;
                        case ZEND_EXT_NOP:
                        case ZEND_NOP:
                                break;
index 83f5bdf9085411ca9266a0cd8fd042c95dad9dc1..551f7366a0da21eca15a2592329ade0faa457be5 100644 (file)
@@ -90,6 +90,8 @@ void init_op_array(zend_op_array *op_array, int initial_ops_size)
 
        op_array->static_variables = NULL;
 
+       op_array->initialized_globals = 0;
+
        zend_llist_apply_with_argument(&zend_extensions, (void (*)(void *, void *)) zend_extension_op_array_ctor_handler, op_array);
 }