Difference between revisions of "PHP"

From HypertWiki
Jump to navigation Jump to search
Line 3: Line 3:
==Reference==
==Reference==
*[http://php.net/ PHP Homepage]
*[http://php.net/ PHP Homepage]
*[http://www.hardened-php.net/ Hardened PHP]: patches to improve PHP security
==Newbie Traps & Pitfalls==
==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:
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:

Revision as of 15:29, 7 August 2005

This article is a stub. You can help HypertWiki by expanding it.

Reference

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.
  • Operators
    • The "is equal to" comparison operator is "==" (as in c/c++), not "="