Hi,

This is a simple patch that allows files like this:

main.php:

<html>
<head>
 <title>template example</title>
</head>
</html>
<body>
<?php
namespace my::template;
// stuff
?>
</body>

to work without parse error.

Greg

P.S. this is the last outstanding namespace issue that I'm aware of aside from the bracket wars, which is 100% philosophical, all the issues fixed by my patches are functional problems in namespaces.
Index: Zend/zend_compile.c
===================================================================
RCS file: /repository/ZendEngine2/zend_compile.c,v
retrieving revision 1.647.2.27.2.41.2.85
diff -u -u -r1.647.2.27.2.41.2.85 zend_compile.c
--- Zend/zend_compile.c 29 Aug 2008 10:17:08 -0000      1.647.2.27.2.41.2.85
+++ Zend/zend_compile.c 12 Sep 2008 19:07:42 -0000
@@ -504,13 +504,17 @@
 }
 
 
-void zend_do_echo(const znode *arg TSRMLS_DC)
+void zend_do_echo(const znode *arg, int is_html TSRMLS_DC)
 {
        zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
 
        opline->opcode = ZEND_ECHO;
        opline->op1 = *arg;
-       SET_UNUSED(opline->op2);
+       if (is_html) {
+               opline->op2.op_type = IS_CONST; /* tell zend_do_namespace that 
INLINE_HTML is OK */
+       } else {
+               SET_UNUSED(opline->op2);
+       }
 }
 
 void zend_do_abstract_method(const znode *function_name, znode *modifiers, 
const znode *body TSRMLS_DC)
@@ -5040,10 +5044,11 @@
        char *lcname;
 
        if (CG(active_op_array)->last > 0) {
-               /* ignore ZEND_EXT_STMT and ZEND_TICKS */
+               /* ignore ZEND_EXT_STMT and ZEND_TICKS and T_INLINE_HTML */
                int num = CG(active_op_array)->last;
                while (num > 0 &&
                       (CG(active_op_array)->opcodes[num-1].opcode == 
ZEND_EXT_STMT ||
+                       (CG(active_op_array)->opcodes[num-1].opcode == 
ZEND_ECHO && CG(active_op_array)->opcodes[num-1].op2.op_type == IS_CONST) ||
                        CG(active_op_array)->opcodes[num-1].opcode == 
ZEND_TICKS)) {
                        --num;
                }
Index: Zend/zend_compile.h
===================================================================
RCS file: /repository/ZendEngine2/zend_compile.h,v
retrieving revision 1.316.2.8.2.12.2.33
diff -u -u -r1.316.2.8.2.12.2.33 zend_compile.h
--- Zend/zend_compile.h 29 Aug 2008 18:12:47 -0000      1.316.2.8.2.12.2.33
+++ Zend/zend_compile.h 12 Sep 2008 19:07:42 -0000
@@ -385,7 +385,7 @@
 void fetch_string_offset(znode *result, const znode *parent, const znode 
*offset TSRMLS_DC);
 void zend_do_fetch_static_member(znode *result, znode *class_znode TSRMLS_DC);
 void zend_do_print(znode *result, const znode *arg TSRMLS_DC);
-void zend_do_echo(const znode *arg TSRMLS_DC);
+void zend_do_echo(const znode *arg, int is_html TSRMLS_DC);
 typedef int (*unary_op_type)(zval *, zval * TSRMLS_DC);
 typedef int (*binary_op_type)(zval *, zval *, zval * TSRMLS_DC);
 ZEND_API unary_op_type get_unary_op(int opcode);
Index: Zend/zend_language_parser.y
===================================================================
RCS file: /repository/ZendEngine2/zend_language_parser.y,v
retrieving revision 1.160.2.4.2.8.2.26
diff -u -u -r1.160.2.4.2.8.2.26 zend_language_parser.y
--- Zend/zend_language_parser.y 29 Aug 2008 17:54:29 -0000      
1.160.2.4.2.8.2.26
+++ Zend/zend_language_parser.y 12 Sep 2008 19:07:42 -0000
@@ -236,7 +236,7 @@
        |       T_GLOBAL global_var_list ';'
        |       T_STATIC static_var_list ';'
        |       T_ECHO echo_expr_list ';'
-       |       T_INLINE_HTML                   { zend_do_echo(&$1 TSRMLS_CC); }
+       |       T_INLINE_HTML                   { zend_do_echo(&$1, 1 
TSRMLS_CC); }
        |       expr ';'                                { zend_do_free(&$1 
TSRMLS_CC); }
        |       T_UNSET '(' unset_variables ')' ';'
        |       T_FOREACH '(' variable T_AS
@@ -556,8 +556,8 @@
 ;
 
 echo_expr_list:
-               echo_expr_list ',' expr { zend_do_echo(&$3 TSRMLS_CC); }
-       |       expr                                    { zend_do_echo(&$1 
TSRMLS_CC); }
+               echo_expr_list ',' expr { zend_do_echo(&$3, 0 TSRMLS_CC); }
+       |       expr                                    { zend_do_echo(&$1, 0 
TSRMLS_CC); }
 ;
 
 
Index: Zend/tests/ns_076.phpt
===================================================================
RCS file: Zend/tests/ns_076.phpt
diff -N Zend/tests/ns_076.phpt
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ Zend/tests/ns_076.phpt      12 Sep 2008 19:07:42 -0000
@@ -0,0 +1,26 @@
+--TEST--
+076: T_INLINE_HTML prior to namespace declaration
+--FILE--
+hi there
+<?php
+
+namespace foo;
+
+class Test {
+  static function f() {
+    var_dump((binary)__NAMESPACE__);
+    include __DIR__ . '/ns_069.inc';
+    var_dump((binary)__NAMESPACE__);
+  }
+}
+
+Test::f();
+
+?>
+===DONE===
+--EXPECT--
+hi there
+string(3) "foo"
+string(0) ""
+string(3) "foo"
+===DONE===
Index: Zend/tests/ns_077.phpt
===================================================================
RCS file: Zend/tests/ns_077.phpt
diff -N Zend/tests/ns_077.phpt
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ Zend/tests/ns_077.phpt      12 Sep 2008 19:07:42 -0000
@@ -0,0 +1,21 @@
+--TEST--
+076: T_ECHO prior to namespace declaration
+--FILE--
+<?php
+echo 'oops';
+namespace foo;
+
+class Test {
+  static function f() {
+    var_dump((binary)__NAMESPACE__);
+    include __DIR__ . '/ns_069.inc';
+    var_dump((binary)__NAMESPACE__);
+  }
+}
+
+Test::f();
+
+?>
+===DONE===
+--EXPECTF--
+Fatal error: Namespace declaration statement has to be the very first 
statement in the script in %sns_077.php on line %d
\ No newline at end of file

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to