4 ms·
I'm sorry to be so negative, but I disagree with a lot of those points. > short_open_tag: Always use the long PHP tags: <?php echo "hello world"; ?> Do not use
by Udo 16y ago
I'm sorry to be so negative, but I disagree with a lot of those points.
> short_open_tag: Always use the long PHP tags: <?php echo "hello world"; ?> Do not use the echo shortcut <?=.
It's just a minor point, but why are we advocating the longer version which is also more difficult to read? It's not like there are typically any other XML PIs in a PHP file, so there is really no potential for confusion here.
> Use Value Objects (VO)
It may be a widely used J2EE pattern, but that in itself is no justification for using it. I love VOs in JavaScript, they're handy and light-weight, they're the core of what's awesome about JSON. But PHP has perfectly good associative arrays that can do the same job, without all the declarative overhead of VOs. If we're not going to implement behavior inside these objects, really what is the point?
> Use Data Access Objects (DAO)
And once again with the J2EE worship. Why?
> Generate code
This has got to be the most unnecessary of all. Sure, if you're going to use lots of VOs and DAO, you'll probably need code generation, but that's just circular logic. But this is also thoroughly besides the point, and it's a performance nightmare. What happened to efficient, terse code? A CGI call in PHP is not made against a static class environment: all this stuff has to be initialized for every single request. At a fundamental level, this betrays a failure to understand the crucial differences between the PHP runtime and, say, a servlet container. It is essential that programmers make use of the individual strengths those systems have, instead of translating Java code and design patterns blindly into whatever environment they happen to work with.
That said, there are very many valid design points that benefit almost any code in any program language. But in the cases above, PHP best practices simply should not be derived from a wish to mimic Java (probably stemming from a misguided attempt to fake the appearance of sophistication and academic validity).