From: Dmitry Stogov Date: Wed, 5 Sep 2007 07:24:52 +0000 (+0000) Subject: Bug #42541 (Check for namespace decl. on first line doesn't work when extended info... X-Git-Tag: RELEASE_2_0_0a1~1880 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=45c6b4db99e82f218a5a91b4d94c6e29fccec5dc;p=php Bug #42541 (Check for namespace decl. on first line doesn't work when extended info is on) --- diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index a017c71084..dc7b2c7f1a 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -4478,7 +4478,15 @@ void zend_do_declare_stmt(znode *var, znode *val TSRMLS_DC) /* {{{ */ * want to tell them to put declare() at the top. */ if (CG(active_op_array)->last > 0) { - zend_error(E_COMPILE_ERROR, "Encoding declaration pragma has to be the very first statement in the script"); + /* ignore ZEND_EXT_STMT */ + int num = CG(active_op_array)->last; + while (num > 0 && + CG(active_op_array)->opcodes[num-1].opcode == ZEND_EXT_STMT) { + --num; + } + if (num > 0) { + zend_error(E_COMPILE_ERROR, "Encoding declaration pragma has to be the very first statement in the script"); + } } convert_to_string(&val->u.constant); if (zend_prepare_scanner_converters(Z_STRVAL(val->u.constant), 1 TSRMLS_CC) == FAILURE) { @@ -5046,7 +5054,15 @@ void zend_do_namespace(znode *name TSRMLS_DC) /* {{{ */ zstr lcname; if (CG(active_op_array)->last > 0) { - zend_error(E_COMPILE_ERROR, "Namespace declaration statement has to be the very first statement in the script"); + /* ignore ZEND_EXT_STMT */ + int num = CG(active_op_array)->last; + while (num > 0 && + CG(active_op_array)->opcodes[num-1].opcode == ZEND_EXT_STMT) { + --num; + } + if (num > 0) { + zend_error(E_COMPILE_ERROR, "Namespace declaration statement has to be the very first statement in the script"); + } } if (CG(current_namespace)) { zend_error(E_COMPILE_ERROR, "Namespace cannot be declared twice");