Not replying to anyone in particular or quoting anything so I'll start
afresh. This is with the topic though, but I'm going to step outside of the
box a bit.

PHP was a template engine at inception. It still is to some degree - hence
braceless syntax. The argument can be made that while the language has
evolved the template engine capabilities of PHP are severely lagging. This
is why smarty and twig exist - and something has gone awry when people are
writing template engines inside of a template engine.

There exists output that needs to be escaped, usually through
htmlentities(). Having PHP auto escape the content is often desirable. In a
given file though it is very unlikely that more than one filter technique.
So instead of a new operator, why not use the existing declare mechanism to
declare a filter?

declare('filter=htmlentities');

With this on the function set for filter will be invoked on the output of
any echo statement or the shortcode for it.  When raw output is still
needed allow print() to output the content bypassing any declared filters
for the file.

This alone would help a great deal, but in addition to this I think having
contextual require statements could also be useful. The most obvious
example:

html_require 'path/to/template/file.phtml';

Contextual file import also opens to the door to pull in code files that
aren't supposed to be echoing anything out, such as class files in most
frameworks. Consider this possiblity

php_require 'path/to/my/classfile.php';

This statement would throw a parse error if there are any <?php ?> or <?=
?> tags at all except a <?php at the very beginning of the file (allowed so
that users of older IDE's can work with the file and have color context
editing intact).  This statement has the potential to allow the engine to
build these files a bit faster since inline_html tokens wouldn't need to be
tracked. Also, there is a security upside I think by prohibiting files that
shouldn't be outputting anything from doing so.

In closing, I see the need and do think it needs to be filled, but I'm not
sure a new operator with multiple arguments is the way to go.

Reply via email to