Difference between revisions of "PHP"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to navigation Jump to search
(→‎Error Messages: REG_EMPTY)
(moved rediscovered HypertWiki content over here, finally)
Line 1: Line 1:
[[Computing]]: [[Software]]: [[PHP]]{{seed}}
+
==Navigation==
[[PHP]] is an interpreted language most commonly used in web sites.
+
[[computing]]: [[software]]: [[programming]]: [[programming languages|languages]] [[PHP]]{{seed}}
==Reference==
+
==Overview==
* [http://php.net/ Official PHP Website]
+
[[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.
* {{wikipedia|PHP}}
 
* [http://wiki.cc/php/Main_Page PHP Wiki]
 
 
 
 
==Related Articles==
 
==Related Articles==
 
* [[Perl vs. PHP]]
 
* [[Perl vs. PHP]]
 
* [[register_globals]]
 
* [[register_globals]]
==Related Things==
+
==Links==
===Coding Resources===
+
===Reference===
 +
* [http://php.net/ Official PHP Website]
 +
* {{wikipedia}}
 +
* [http://wiki.cc/php/Main_Page PHP Wiki]
 +
===Projects===
 +
* [http://www.hardened-php.net/ Hardened PHP]: patches to improve PHP security
 +
====Users Groups====
 +
* [http://www.tripug.org/ Triangle PHP Users Group]: [[The Triangle, NC]]
 +
====Coding Resources====
 
* [[wikipedia:PHP Extension and Application Repository|PHP Extension and Application Repository]] (PEAR)
 
* [[wikipedia:PHP Extension and Application Repository|PHP Extension and Application Repository]] (PEAR)
 
** [http://pear.php.net/ official web site]
 
** [http://pear.php.net/ official web site]
===Users Groups===
+
===News & Views===
* [http://www.tripug.org/ Triangle PHP Users Group]: [[The Triangle, NC]]
 
 
 
==Links==
 
 
* '''2006-07-22''' [http://blog.case.edu/gps10/2006/07/22/why_global_variables_in_php_is_bad_programming_practice Why Global Variables in PHP is Bad Programming Practice]
 
* '''2006-07-22''' [http://blog.case.edu/gps10/2006/07/22/why_global_variables_in_php_is_bad_programming_practice Why Global Variables in PHP is Bad Programming Practice]
 
* [http://www.ukuug.org/events/linux2002/papers/html/php/ Experiences of Using PHP in Large Websites]
 
* [http://www.ukuug.org/events/linux2002/papers/html/php/ Experiences of Using PHP in Large Websites]
 
* [http://dagbrown.livejournal.com/19338.html un-PHP-ing my web site]: a LiveJournal entry critical of PHP
 
* [http://dagbrown.livejournal.com/19338.html 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.
 +
*Operators
 +
**The "is equal to" comparison operator is "==" (as in c/c++), not "="
 
==Notes==
 
==Notes==
 
One of the major weaknesses of PHP as a serious programming language is its lack of any way to require variable declaration before usage -- the equivalent of "use strict;" in [[Perl]] or "Option Explicit" in [[Visual Basic]]. [http://www.wellho.net/forum/Writing-PHP/use-strict.html Here] is a brief discussion of this problem, with a workaround which might be useful in some situations (but not if you need to turn off warnings for other reasons, such as needing to suppress messages about duplicate http headers).
 
One of the major weaknesses of PHP as a serious programming language is its lack of any way to require variable declaration before usage -- the equivalent of "use strict;" in [[Perl]] or "Option Explicit" in [[Visual Basic]]. [http://www.wellho.net/forum/Writing-PHP/use-strict.html Here] is a brief discussion of this problem, with a workaround which might be useful in some situations (but not if you need to turn off warnings for other reasons, such as needing to suppress messages about duplicate http headers).

Revision as of 14:23, 15 October 2007

Navigation

computing: software: programming: languages PHP

This page is a seed article. You can help HTYP water it: make a request to expand a given page and/or donate to help give us more writing-hours!

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.

Related Articles

Links

Reference

Projects

Users Groups

Coding Resources

News & Views

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 "="

Notes

One of the major weaknesses of PHP as a serious programming language is its lack of any way to require variable declaration before usage -- the equivalent of "use strict;" in Perl or "Option Explicit" in Visual Basic. Here is a brief discussion of this problem, with a workaround which might be useful in some situations (but not if you need to turn off warnings for other reasons, such as needing to suppress messages about duplicate http headers).

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.