<p>I'm looking to improve my PHP coding and am wondering what PHP-specific techniques other programmers use to improve productivity or workaround PHP limitations.</p>

<p>Some examples:</p>

<ol>
<li><p>Class naming convention to handle namespaces: <code>Part1_Part2_ClassName</code> maps to file <code>Part1/Part2/ClassName.php</code></p></li>
<li><p><code>if ( count($arrayName) ) // handles $arrayName being unset or empty</code></p></li>
<li><p>Variable function names, e.g. <code>$func = 'foo'; $func($bar); // calls foo($bar);</code></p></li>
</ol>

My experience with PHP has taught me a few things. To name a few:
Always output errors. These are the first two lines of my typical project (in development mode):
```
```
ini_set('display_errors', '1');
error_reporting(E_ALL);
```
```
Never use
automagic
. Stuff like autoLoad may bite you in the future.
Always require dependent classes using
```
require_once
```
. That way you can be sure you'll have your dependencies straight.
Use
```
if(isset($array[$key]))
```
instead of
```
if($array[$key])
```
. The second will raise a warning if the key isn't defined.
When defining variables (even with
```
for
```
cycles) give them verbose names (
```
$listIndex
```
instead of
```
$j
```
)
Comment, comment, comment. If a particular snippet of code doesn't seem obvious, leave a comment. Later on you might need to review it and might not remember what it's purpose is.
Other than that, class, function and variable naming conventions are up to you and your team. Lately I've been using
Zend Framework's naming conventions
because they feel right to me.
Also, and when in development mode, I set an error handler that will output an error page at the slightest error (even warnings), giving me the
full backtrace
.