]> granicus.if.org Git - php/commitdiff
Bug #42541 (Check for namespace decl. on first line doesn't work when extended info...
authorDmitry Stogov <dmitry@php.net>
Wed, 5 Sep 2007 07:24:52 +0000 (07:24 +0000)
committerDmitry Stogov <dmitry@php.net>
Wed, 5 Sep 2007 07:24:52 +0000 (07:24 +0000)
Zend/zend_compile.c

index a017c7108426325aa0091cd3c24fc32b8cb37bed..dc7b2c7f1a3943fa97296413b6c246b1b862b8b9 100644 (file)
@@ -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");