PHP: Difference between revisions

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
No edit summary
 
(24 intermediate revisions by the same user not shown)
Line 9: Line 9:
Note that much of the information on this page is somewhat outdated; PHP continues to be actively developed and improved.
Note that much of the information on this page is somewhat outdated; PHP continues to be actively developed and improved.
===subpages===
===subpages===
* [[/arrays]]
{| class="wikitable sortable"
* [[/CLI]]: using PHP from a [[command line interface]]
! subpage name || type || about
* [[/criticism]]: why PHP is bad
{{!-!}} [[/arrays/]] || concept
* [[/debugging/interactive]]
{{!-!}} [[/CLI/]] || how-to || using PHP from a [[command line interface]]
* [[/file]]-handling
{{!-!}} [[/criticism/]] || community || why PHP is bad
* [[/frameworks]]
{{!-!}} [[/debugging/]] || how-to || especially [[/debugging/interactive|/interactive]]
* [[/GUI]]: graphical interface programming in PHP
{{!-!}} <code>[[/declare/]]()</code>: altering PHP behavior within a file, including strict typing
* [[/interface]] keyword
{{!-!}} <code>[[/enum/]]</code> || type/concept
* [[/trait]] keyword/concept
{{!-!}} [[/file/]]-handling || how-to
* [[/type declaration]]
{{!-!}} [[/frameworks/]]
{{!-!}} [[/function variable/]]: a variable can be a reference to a function
{{!-!}} [[/fx/]]: function documentation/notes
{{!-!}} [[/GUI/]]: graphical interface programming in PHP
{{!-!}} [[/installing/]]
{{!-!}} [[/inheritance/]] || syntax || rules
{{!-!}} <code>[[/interface/]]</code> || keyword
{{!-!}} [[/lib/]]raries || concept: collections of related functions that are provided as add-on modules
{{!-!}} [[/namespace/]]s || keyword/concept
{{!-!}} [[/operator/]]s || syntax || there are some relatively obscure ones that aren't well-indexed in the official documentation
{{!-!}} [[/referencing/]]: how variable references work
{{!-!}} <code>[[/ReflectionClass/]]</code> || native class || especially <code>[[/ReflectionClass/getParentClass|ReflectionClass::getParentClass]]()</code>
{{!-!}} <code>[[/resource/]]</code> || syntax/concept
{{!-!}} {{l/pfx|/resource/|stream}} || a particular type of resource
{{!-!}} [[/string/]] || type/functions
{{!-!}} <code>[[/trait/]]</code> || keyword/concept || including "[[/trait/use|use]]" in the context of traits
{{!-!}} [[/type declaration/]]
{{!-!}} <code>[[/use/]]</code> || keyword || "use" has 3 different meanings in PHP
{{!-!}} [[/XML/]] || libraries
|}


==Related Articles==
==Related Articles==
Line 24: Line 43:
* [[Perl vs. PHP]]: comparisons between the two languages
* [[Perl vs. PHP]]: comparisons between the two languages
* [[register_globals]]
* [[register_globals]]
===offsite===
* [[wooz:2021/11/25/PHP documentation gripe]]: a misunderstanding about type-compatibility in method overrrides


==Links==
==Links==
===Reference===
===Reference===
* [http://php.net/ Official]
* [http://php.net/ Web]
** [http://php.net/manual/ Manual]
** [http://php.net/manual/ Manual]
*** [http://php.net/manual/en/langref.php Language Reference]
*** [http://php.net/manual/en/langref.php Language Reference]
**** [http://php.net/manual/en/language.constants.predefined.php Magic constants]
**** [http://php.net/manual/en/language.constants.predefined.php Magic constants]
**** [https://www.php.net/manual/en/language.namespaces.rules.php Name resolution rules]
**** parameter types: [http://php.net/manual/en/functions.arguments.php Function arguments] (aka type hinting)
**** parameter types: [http://php.net/manual/en/functions.arguments.php Function arguments] (aka type hinting)
**** [https://www.php.net/manual/en/reserved.variables.php Predefined variables]
* {{wikipedia}}
* {{wikipedia}}
* [http://wiki.cc/php/Main_Page PHP Wiki]
 
===Social===
* [https://twitter.com/official_php Twitter]
 
===Projects===
===Projects===
* [https://www.phptherightway.com/ PHP The Right Way]: good practices and patterns
* [https://www.phptherightway.com/ PHP The Right Way]: good practices and patterns
Line 46: Line 72:
** [http://pear.php.net/ Official]
** [http://pear.php.net/ Official]
** {{wikipedia|PEAR}}
** {{wikipedia|PEAR}}
==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''' <u>child</u> '''extends''' <u>parent</u>), 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 "="
==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).
php -l {{arg|filename.php}}
will give a boolean on file syntax. ([https://toot.cat/@js0000/106377779222214992 source]; to be tested)
==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 [http://www.laurikari.net/tre/api.html 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.

Latest revision as of 23:50, 26 March 2026

<hide> page type::article thing type::computer language language type::interpreted </hide>

About

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

Note that much of the information on this page is somewhat outdated; PHP continues to be actively developed and improved.

subpages

subpage name type about
arrays concept
CLI how-to using PHP from a command line interface
criticism community why PHP is bad
debugging how-to especially /interactive
declare(): altering PHP behavior within a file, including strict typing
enum type/concept
file-handling how-to
frameworks
function variable: a variable can be a reference to a function
fx: function documentation/notes
GUI: graphical interface programming in PHP
installing
inheritance syntax rules
interface keyword
libraries concept: collections of related functions that are provided as add-on modules
namespaces keyword/concept
operators syntax there are some relatively obscure ones that aren't well-indexed in the official documentation
referencing: how variable references work
ReflectionClass native class especially ReflectionClass::getParentClass()
resource syntax/concept
stream a particular type of resource
string type/functions
trait keyword/concept including "use" in the context of traits
type declaration
use keyword "use" has 3 different meanings in PHP
XML libraries

offsite

Reference

Social

Projects

  • PHP The Right Way: good practices and patterns
  • Hardened PHP: patches to improve PHP security
  • 3v4l.org "is an online shell that allows you to run your code on my server. I compiled more than 200 different PHP versions (every version released since 4.3.0) plus HHVM for you to use."

Development Tools

Users Groups

Coding Resources