]> granicus.if.org Git - php/commitdiff
Substitute persistent constants by their values at compile time. (Matt)
authorDmitry Stogov <dmitry@php.net>
Fri, 25 Jul 2008 04:54:56 +0000 (04:54 +0000)
committerDmitry Stogov <dmitry@php.net>
Fri, 25 Jul 2008 04:54:56 +0000 (04:54 +0000)
Zend/zend_compile.c
Zend/zend_compile.h

index dfd9306394a34bcfdcc8752120552735e3794c00..7057101554015f4af9da7dc96982287daa974c31 100644 (file)
@@ -4009,6 +4009,13 @@ static zend_constant* zend_get_ct_const(zval *const_name TSRMLS_DC) /* {{{ */
        if (c->flags & CONST_CT_SUBST) {
                return c;
        }
+       if ((c->flags & CONST_PERSISTENT) &&
+           !CG(current_namespace) &&
+           !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION) &&
+           Z_TYPE(c->value) != IS_CONSTANT &&
+           Z_TYPE(c->value) != IS_CONSTANT_ARRAY) {
+               return c;
+       }
        return NULL;
 }
 /* }}} */
@@ -5546,12 +5553,14 @@ void zend_do_use(znode *ns_name, znode *new_name, int is_global TSRMLS_DC) /* {{
 void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC) /* {{{ */
 {
        zend_op *opline;
+       zend_constant *c;
 
        if(Z_TYPE(value->u.constant) == IS_CONSTANT_ARRAY) {
                zend_error(E_COMPILE_ERROR, "Arrays are not allowed as constants");
        }
 
-       if (zend_get_ct_const(&name->u.constant TSRMLS_CC)) {
+       c = zend_get_ct_const(&name->u.constant TSRMLS_CC);
+       if (c && (c->flags & CONST_CT_SUBST)) {
                zend_error(E_COMPILE_ERROR, "Cannot redeclare constant '%R'", Z_TYPE(name->u.constant), Z_UNIVAL(name->u.constant));
        }
 
index 0f8d6a82081d8bcd0473567a19f2ba49618d3c49..df64ee090fd009374e1e4635096105b72fe0989b 100644 (file)
@@ -789,6 +789,9 @@ END_EXTERN_C()
 /* generate ZEND_DECLARE_INHERITED_CLASS_DELAYED opcode to delay early binding */
 #define ZEND_COMPILE_DELAYED_BINDING                   (1<<4)
 
+/* disable constant substitution at compile-time */
+#define ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION  (1<<5)
+
 /* The default value for CG(compiler_options) */
 #define ZEND_COMPILE_DEFAULT                                   ZEND_COMPILE_HANDLE_OP_ARRAY