PHP

Navigation
computing: software: programming: languages: PHP

Overview
PHP is an interpreted programming language most commonly used in web sites. It is the language in which the MediaWiki, Drupal, and ZenCart web software packages, among many others, are written.

subpages

 * /arrays

Related Articles

 * Apache and PHP: getting the two of them to work together nicely
 * Perl vs. PHP: comparisons between the two languages
 * register_globals

Reference

 * Official PHP Website
 * PHP Wiki
 * PHP Wiki

Projects

 * Hardened PHP: patches to improve PHP security

Development Tools

 * phpUnderControl - "Continuous Integration for PHP"

Users Groups

 * Triangle PHP Users Group: The Triangle, NC

Coding Resources

 * PHP Extension and Application Repository (PEAR)
 * official web site

News & Views

 * 2006-07-22 Why Global Variables in PHP is Bad Programming Practice
 * Experiences of Using PHP in Large Websites
 * un-PHP-ing my web site: a LiveJournal entry critical of PHP

Newbie Traps & Pitfalls
PHP will let you get away with a lot of syntax mistakes which are perfectly valid code (often creating unexpected variables in the process) but not what you intended. Most of the following produced no immediate error messages; the code simply wouldn't work, and it took me several edit-upload-run cycles to find each problem. Here are some mistakes I made when re-learning PHP in 2005 after not using it since 1997:
 * Classes:
 * Member vars and functions must always be referred to using $this->FunctionName
 * However, var members do not take a $ prefix: $this->varName
 * If you pass an object to a function, the function will be operating on a copy of the object unless the function is called with the object passed as a reference: CalledFunction(&$objName);. The function declaration itself needs no modifications.
 * If the function is expected to store the object for later use (e.g. it is a class constructor), the function must also use a reference when saving the object: $this->localName =& $iObjectParam;. Otherwise (again) it will be using a copy, not the original.
 * In a child function (class child extends parent ), if the parent has member variables declared as "private" and you attempt to access them with $this->varname, PHP will silently create new member variables for the child scope rather than referencing the old ones or generating an error. (Change the var declarations to "protected".)
 * Operators:
 * The "is equal to" comparison operator is "==" (as in c/c++), not "="

Error Messages
some of these are not found in the PHP documentation
 * REG_EMPTY: regex-related, but not sure what it means; it may reflect a difference between Perl-style regex (preg_* functions) and grep-style regex (ereg* functions). I changed the expression "('|")" to "['"]", and this seemed to solve the problem.
 * REG_ERANGE: This error appears to originate in the regex library, and means "Invalid character range, e.g. ending point is earlier in the collating order than the starting point." (Documented here)
 * In one case, this was caused by having a forward-slash ("/") in the bracketed list of possible characters; escaping the forward slash fixed the problem.