Common Style Mistakes, Part 1
Subject:   style rules
Date:   2003-06-14 16:59:40
From:   anonymous2
No need to fussily always use the ugly <?php and other default values. To make your code more transportable write an include file that sets all the php config directives to what your app needs. If your code can't change them it can check and spit out an error.

ini_set('short_open_tag', 1);
assert(ini_get('short_open_tag') == 1);

I think it's a good idea to do this for any significant PHP application, rather than rely on whatever happens to be in the php.ini file when you wrote the code, especially in a shared hosting environment.

As for chaining function calls, years of experience with Lisp and C -- both much older than PHP -- show that proliferating temporary variables is an even worse idea. The author wrote a deliberately ugly and obfuscated example, but with some indenting the code can be perfectly obvious. Anyone who can't follow a few nested function calls should not be writing important code anyway.

Try writing in a language that doesn't have functions that return values and you'll quickly see how tedious that can be.

The ternary operator condition ? expression : expression lends itself to misuse, but there's nothing inherently wrong with using it inside a function call or anywhere else. The order of evaluation is well-defined. Sometimes simply enclosing the whole thing in parentheses makes it clearer. Again indenting and clarity in writing go a long way.

Greg Jorgensen

1 to 1 of 1
1 to 1 of 1