Appendix C. Code debugging

This appendix describes issues concerning OPT template debugging.

C.1. Template compilation

The most common problems are connected with parsing the template into a node tree. The compiler reports every not closed tags and pays attention to the closing order. If an error occurs, the exception is returned and the result file is not generated. If you get a message Fatal error: Call to a member function restoreBlock() on a non-object, this also means some kind of unclosed tag. However, report it to the OPT authors in the bugtracker, with the template that caused problems.

The compiler does not report the mistakes in instruction names. In this case, it creates an unknown node for it, which is accepted by the OPT tech notes. If you see a piece of code that is not executed and its content "disappears", check the instruction name! You may have made here a mistake.

C.2. Expression compilation

Starting from 1.0.0-RC2 version, OPT detects and reports most of the syntax errors in the expressions, before generating invalid PHP code. In such situation, the compiler throws the exception: 108 (Unexpected token: OPCODE_TOKENNAME (token value) in expression (invalid expression)). It means you try to use this token in invalid place.

Sometimes the invalid expression is not detected by the reporting system and the syntax rules implemented in OPT. In this case you will get a PHP parse error.

C.3. Encoding

The parser changes the error reporting level to E_ALL & ~E_NOTICE during the template execution. This means that PHP notices are not reported in the templates, which is accepted by the OPT tech notes. The original error level is restored after the template is executed.

In order to detect the Unicode encoding by many browsers, you have to set the charset configuration directive and call optClass::httpHeaders() method. Without it, the browser will not detect the valid encoding, even if it is specified in the META section.

Important information: OPT does not affect the XHTML document type definition or xml declaration. If you notice some newlines there, they must be added by your script or your templates.