PHP Programm Language Notes

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a general-purpose
scripting language that is especially suited for web development. These are
just some quick notes on various bits and bobs.

Page Contents

Check Your Code

PHP Synax checking

Just used the php -l <file> to syntax check a file.

PHP Code Sniffer

PHP_CodeSniffer by Squiz Pty Ltd. (http://www.squiz.net). Helps
detect and fix violations of a defined set of coding standards.

Autoloading Classes

Lets say you have a PHP file called jehtech.class.php in which
the class jehtech is defined. Rather than including it in
every script PHP can dynamically load it using a search pattern you
sepecify in the autoload() function.

If your directory structure, for example, mirrored the name space you
could split the class name on the namespace seperator ('\')
and locate it that way.

Stream Filters

I know everyone frowns on using printf style debugging, but I still
like it. What I had is debug output that has no indentation because
it is harder to read. So here is a tiny little debug class that
is a stream filter that you can associate with any PHP resource.
When you print to it it will insert left-padding at the indent
you are currently at.

A filter is a final piece of code which may perform operations on data as it is being read from or written to a stream. Any number of filters may be stacked onto a stream.