77 points · by nikic · 14y ago · 39 comments
[1] http://alexrosen.com/blog/2011/05/sponge-learning/
edit: grammar.
The fact that it is written in PHP is nice because it allows you to use it in existing PHP projects in an environment you are already familiar with. I think the fact that it is written in PHP is less important than the fact that it can be used in PHP (e.g. it would be equally useful as a PHP extension written in C).
But more formally, a self-hosting compiler says stuff about the language per se, see also http://en.wikipedia.org/wiki/Bootstrapping_(compilers).
That it's Turing-complete and can write to a file? I think all it really says is that somebody was hard-headed enough to do it.
And there is nothing bad with this. It is just that many authors don't want to articulate on this and are trying to come up with some artificial rationales.
I saw this in Horde, the other day; mixed in with the usual PHP tags they had added their own XML tags for doing "if/else" type things in the template. What is the purpose of that?
...which I think is retarded and anal, since the important part is separation of business logic and presentation. There is bound to be some level of display logic, which is why most template languages have loops and conditionals. But if you are going that far, why not just use PHP? It is arguably a very good template language.
If you're making a template language for use in a SaaS system, you'd want to perhaps allow echo, but not file_put_contents.
1: http://www.smarty.net/ 2: https://en.wikipedia.org/wiki/Inner-platform_effect
Disclaimer: I've never had to use this, so don't know what the limitations and pitfalls are for this, and there may be security concerns that I'm unaware of.
[1] http://www.php.net/manual/en/ini.core.php#ini.disable-functi...
I believe it's much faster too.
The parser is more for analyzers that are not interested in the precise formatting of the code, but want to look at the code from a higher level perspective.
For example, if you want to do control flow analysis and type inference working directly on the tokens would be really hard. An Abstract Syntax Tree makes this kind of work much easier, as you don't have to think about the tiny details of the language.
Certainly this project doesn't get us there immediately, but might give some neat ideas for future PHP versions to incorporate.
http://us3.php.net/manual/en/function.token-get-all.php http://us3.php.net/manual/en/function.token-name.php
Very cool nonetheless.
Well done with the project--I have a use case for it regarding enforcing PHP style guide @ $work.