PHP Code

Coding standards are guidelines, generally stylistic, that give source code universal qualities. These universal qualities make the code more compatible, maintainable, and readable than it would otherwise be. Some coding standards form among the wider communities center o­n a particular language, such as PHP. Other coding standards are specific to development teams.

PHP is a type of programming language. While Rasmus Lerdorf originally conceived this widely used scripting language for web development, it has since grown into a more versatile tool. The language’s popularity has given rise to a set of coding standards that have become widely accepted. However, there are platforms that make use of PHP, such as the Drupal content management system, that set forth their own coding standard. These various coding standards can make it difficult for the PHP coder.

An example of where these standards differ is in the use of PHP code tags, which programmers use to delimit the start and end of PHP code. In a standalone file, this delimitation serves o­nly to mark the entire file as PHP, such as HTML tags in an HTML-only web file. In complex scenarios, programmers must combine multiple languages, such as HTML, JavaScript, and PHP. In these cases, the code tags serve to delimit the start and end of PHP code blocks from the blocks of other languages.

The default form of a beginning PHP code tag is “< ?PHP” and it is given closure using “?>”, minus the quotes. However, the shorthand form of “” has become the preferred coding standard. Nevertheless, in order to avoid conflicts, the popular platform Drupal requires PHP code blocks opened with the traditional “< ?PHP”. To further confuse matters, as of Drupal 4.7, a closing tag, “?>”, at the end of a file is purposefully omitted. This is an inconsistent problem across PHP-using platforms that cause coders to keep track of the differences.