4 ms·
I generally like PHP but am not a very advanced user, so I'm interested: what shortcomings do you see?
by cousin_it 17y ago
I generally like PHP but am not a very advanced user, so I'm interested: what shortcomings do you see?
- eru 17y agohttp://www.google.com/search?q=php+shortcomings http://www.google.com/search?q=php+shortcomings
- cousin_it 17y agoeru, your answer is too generic - I could have googled that myself. I'm interested specifically in the shortcomings of PHP as a templating system.
- eru 17y agoOK. E.g. PHP does not check whether your templates are valid HTML (or even just half-way sane tag soup) at all. And you need to put a $ in front of every variable. Seems like someone did not know how to write a parser..
- cousin_it 17y agoDo other template engines, e.g. Smarty, check HTML validity? I tried looking at the docs and it wasn't apparent.
- eru 17y agoI would guess the PLT webserver can do so. At least it will statically avoid unclosed tags, since it's based on s-expressions. http://docs.plt-scheme.org/web-server/run_ss.html#%28part._insta%29 http://docs.plt-scheme.org/web-server/run_ss.html#%28part._i...
- randallsquared 17y agoThere are two major problems for me: one is that markup filled with "<?=$varname;?>" is harder to parse than markup filled with "{varname}"; for a designer, those extra characters are totally extraneous, and they're not even balanced the way all other kinds of special markup are in HTML or XML. Secondly, there's nothing in PHP that guides one away from packing more and more functionality into the template instead of the template's caller; it's easy to find snippets of PHP that do something "cool" online, and it's hard to explain to your designer why they shouldn't use them. So, too verbose and less maintainable, is what it boils down to.
- cousin_it 17y agoThanks! I won't start using Smarty because of that, but those sound like valid reasons for bigger projects.
- jbm 17y agoI'm not sure why you believe that it is necessary to do stuff like <?=$varname;?>. Certainly, a competent PHP programmer can use file operations and str_replace to do templating; it's pretty much what I do right now. The template for a dog-related site I'm working on looks like this: <div class="dog" id="dog_{{__id__}}"> <h1 class="name">{{__name__}}</h1> <p class="sex">{{__sex__}}</p> <p class="breed">{{__breed__}}</p> <p class="images">{{__pictures__}}</p> <div class="description">{{__description__}}</div> </div> (The formatting appears to be lost; accept my apologies) That said, I am also working on fixing a restaurant site that a friend programmed, and it is littered with the type of disgusting syntax you mention. It's the difference between a designer who does snippets of PHP and a programmer.
- randallsquared 17y agoYou're not arguing against me, but with me. ;) The article suggested that it was obviously a bad idea to write a templating engine in PHP, since PHP is already in the category of "templating engine". As you point out, it's easy to implement a template system in PHP that's better to use than raw PHP would be.