]> granicus.if.org Git - php/commitdiff
- Support importing constants. e.g.:
authorAndi Gutmans <andi@php.net>
Fri, 8 Mar 2002 10:58:24 +0000 (10:58 +0000)
committerAndi Gutmans <andi@php.net>
Fri, 8 Mar 2002 10:58:24 +0000 (10:58 +0000)
<?php

class MyOuterClass {
const Hello = "Hello, World\n";
}

import const Hello from MyOuterClass;
print Hello;

Zend/zend_execute.c

index c9c6a6b272382e3fb296d014332a846a821bbcf3..4c9dea3cb5751125c8e48241720e4b2455a3fe76 100644 (file)
@@ -1462,9 +1462,52 @@ binary_assign_op_addr: {
                        case ZEND_IMPORT_CONST:
                                {
                                        zend_class_entry *ce;
+                                       zval **import_constant;
+                                       zend_constant c;
                                        
                                        ce = EX(Ts)[EX(opline)->op1.u.var].EA.class_entry;
-
+                                       if (EX(opline)->op2.op_type != IS_UNUSED) {
+                                               char *const_name_strval;
+                                               int const_name_strlen;
+                                               
+                                               const_name_strval = EX(opline)->op2.u.constant.value.str.val;
+                                               const_name_strlen = EX(opline)->op2.u.constant.value.str.len;
+                                               
+                                               if (zend_hash_find(&ce->constants_table, const_name_strval, const_name_strlen + 1, (void **) &import_constant)==FAILURE) {
+                                                       zend_error(E_ERROR, "Import: constant %s not found", const_name_strval);
+                                               }
+                                               c.value = **import_constant;
+                                               zval_copy_ctor(&c.value);
+                                               c.flags = CONST_CS;
+                                               c.name = zend_strndup(const_name_strval, const_name_strlen);
+                                               c.name_len = const_name_strlen + 1;
+
+                                               if (zend_register_constant(&c TSRMLS_CC) == FAILURE) {
+                                                       zend_error(E_ERROR, "Import: unable to register constant %s", const_name_strval);
+                                               }
+                                       } else {
+                                               HashPosition pos;
+                                               char *key;
+                                               uint key_length;
+                                               int key_type;
+                                               ulong dummy;
+
+                                               zend_hash_internal_pointer_reset_ex(&ce->constants_table, &pos);
+                                               while(zend_hash_get_current_data_ex(&ce->constants_table, (void **)&import_constant, &pos) == SUCCESS) {
+                                                       key_type = zend_hash_get_current_key_ex(&ce->constants_table, &key, &key_length, &dummy, 0, &pos);
+
+                                                       c.value = **import_constant;
+                                                       zval_copy_ctor(&c.value);
+                                                       c.flags = CONST_CS;
+                                                       c.name = zend_strndup(key, key_length - 1);
+                                                       c.name_len = key_length;
+
+                                                       if (zend_register_constant(&c TSRMLS_CC) == FAILURE) {
+                                                               zend_error(E_ERROR, "Import: unable to register constant %s", key);
+                                                       }
+                                                       zend_hash_move_forward_ex(&ce->constants_table, &pos);
+                                               }
+                                       }
                                        NEXT_OPCODE();
                                }
                        case ZEND_FETCH_CLASS: