This page describes the syntax of the PHP programming language based on the definitions of the language in Programming PHP by Rasmus Lerdorf, and Kevin Tatroe, published by O'Reilly Publishing. Since PHP is still a rapidly evolving programming language, the syntax presented here is for PHP 4.
For a quick, concise reference to terms used through out this page, see [ php.glossary.html ] which contains meta-linguistic terms, lexemes, and keyword definitions based on the C++ glossary found at [ c++.glossary.html ] with the appropriate adaptations to PHP.
Commenting code in PHP can be achieved in three different styles. The first two styles are the C/C++ style of comments, and the third commenting style used in PHP is the Shell style comments. These three styles of commenting are quite universal through out computer science. C/C++/Java programmers, and Unix Shell programmers do not have to learn a new style of commenting in order to comment PHP code. This allows these programmers to comment PHP with a comment style they are most familiar or comfortable with.
C comment containing all characters for comments except for the terminating */.
This is the string of all no eol characters in the comments.
For various styles of comments in PHP, see [ php.samples.html#PHP comments ] .
Note: Just as a quick point, the HTML code generated by PHP will not contain the comments. The comments are only on the server side for the programmer, so do feel free to comment the code for better readability and do not concern having comments affect the bandwidth or time it takes to load the generated HTML.
For the definitions of letter, underscore, and digit, see [ Lexemes in intro_ebnf ] for details.
Note: PHP allows for the use of ASCII codes from 0x7F (127) to 0xFF (255) for valid characters to begin an identifier with. To represent the i'th ASCII character, the notation char_nbr(i) is used.
For various examples of variables in PHP, see [ php.samples.html#PHP variables ] .
Note: Anonymous functions are like LISP lambda expressions. They are functions created on the fly inside an expression. The result can be assigned to a variable or passed as a parameter.
See the examples on using anonymous functions at [ php.samples.html#anonymous_functions ] .
For ignore_case, see [ ignore_case in comp.text.ASCII ] for more details.
See function semantics at [ php.semantics.html#functions ] for more details.
For various examples of functions in PHP, see [ php.samples.html#PHP functions ] .
The class name "stdClass" is reserved and cannot be used as an identifier for a class.
Note: In PHP, there is no concept of private, public, or protected member functions or properties.
For a class example, see [ php.samples.html#PHP classes ] .
For examples of constants, see [ php.samples.html#PHP constants ] .
PHP Data Types
In PHP the range of integers is between -2147483648 and 2147483647. An interesting note about PHP and integers, when the value assigned goes outside these minimum/maximum boundaries, the value is automatically converted to floating point.
In PHP if a variable is assigned a value 7 or 7., echoing to the browser will display 7.
Note: The sentinel must be the same on both sides, opening and closing the heredoc.
Compound Data Types
For arrays and objects, see [ php.misc.html#compound_types ] .
PHP Special Types
This special type is used to represent a variable that does not contain any value, and is similar to undef in Perl and 'None' in Python.
The predefined PHP function, is_null() allows for testing whether or not a variable holds a NULL value or not.
For the PHP special type, resource, see [ php.misc.html#resource_type ] .
PHP Expressions and Operators
|19||Non Associative||new||Creates a new object|
|18||Right Associative||[||Array subscript|
|17||Right Associative||!||Logical NOT|
|17||Right Associative||~||Bitwise NOT|
|17||Right Associative||(int),(double),(string),(array),(object)||Cast type|
|17||Right Associative||@||Inhibit error reporting|
|15||Left Associative||.||String concatenation|
|14||Left Associative||<<||Bitwise SHIFT LEFT|
|14||Left Associative||>>||Bitwise SHIFT RIGHT|
|13||Non Associative||<,<=||Less Than, Less Than or Equal To|
|13||Non Associative||>,>=||Greater Than, Greater Than or Equal To|
|12||Non Associative||==||Value Equality|
|12||Non Associative||!=,<>||Value Inequality|
|12||Non Associative||===||Type and Value Equality|
|12||Non Associative||!==||Type and Value Inequality|
|11||Left Associative||&||Bitwise AND|
|10||Left Associative||^||Bitwise XOR|
|9||Left Associative|||||Bitwise OR|
|8||Left Associative||&&||Logical AND|
|7||Left Associative||||||Logical OR|
|6||Left Associative||?:||Conditional Operator|
|5||Left Associative||=||Assignment Operator|
|5||Left Associative||+=,-=,*=,/=,.=,%=,&=,|=,^=,~=,<<=,>>=||Assignment with Operation|
|4||Left Associative||and||Logical AND|
|3||Left Associative||xor||Logical XOR|
|2||Left Associative||or||Logical OR|
|1||Left Associative||,||List separation|
S(E,Op) = E Op E Op E Op ... E
The rule above means that 'casts' are done before multiplication and division, and that multiplication and division are done from left to right.
Even though PHP is a weak typed language, there are ways to specify a type for a variable. We have the following casting operators:
Compound Data Types
Flow Control Statements
For information on array key see [ php.misc.html#array_keys ] .
See notes on the declare function for more information at [ php.misc.html ] .
Posix Regular Expressions
Note: eregi is just the case-insensitive form of ereg.
Note: eregi_replace is just the case-insensitive form of ereg_replace.
Perl Regular Expressions
Please visit [ php.misc.html#perl_regex_todo ] .
. . . . . . . . . ( end of section The Syntax of PHP) <<Contents | End>>