Error Control Operators

Examples: PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored. If you have set a custom error handler function with set_error_handler() then it will still get called, but this custom error handler can (and should) call error_reporting() which will return 0 when the call that triggered the error was preceded by an @. If the track_errors featu

Assignment Operators

Examples: The basic assignment operator is "=". Your first inclination might be to think of this as "equal to". Don't. It really means that the left operand gets set to the value of the expression on the right (that is, "gets set to"). The value of an assignment expression is the value assigned. That is, the value of "$a = 3" is 3. This allows you to do some tricky things: <?php $a = ($b = 4) + 5; // $a is equal to 9 now, and $b has been set to 4. ?>

Bitwise Operators

Examples: Bit shifting in PHP is arithmetic. Bits shifted off either end are discarded. Left shifts have zeros shifted in on the right while the sign bit is shifted out on the left, meaning the sign of an operand is not preserved. Right shifts have copies of the sign bit shifted in on the left, meaning the sign of an operand is preserved. Use parentheses to ensure the desired precedence. For example, $a & $b == true evaluates the equivalency then the bitwise and

Arithmetic Operators

Examples: The division operator ("/") returns a float value unless the two operands are integers (or strings that get converted to integers) and the numbers are evenly divisible, in which case an integer value will be returned. Operands of modulus are converted to integers (by stripping the decimal part) before processing. The result of the modulus operator % has the same sign as the dividend — that is, the result of $a % $b will have the same sign as $a. For exam

Type Juggling

Examples: PHP does not require (or support) explicit type definition in variable declaration; a variable's type is determined by the context in which the variable is used. That is to say, if a string value is assigned to variable $var, $var becomes a string. If an integer value is then assigned to $var, it becomes an integer. An example of PHP's automatic type conversion is the addition operator '+'. If either operand is a float, then both operands are evaluated as

Operator Precedence

Examples: Associativity <?php $a = 3 * 3 % 5; // (3 * 3) % 5 = 4 // ternary operator associativity differs from C/C++ $a = true ? 0 : true ? 1 : 2; // (true ? 0 : true) ? 1 : 2 = 2 $a = 1; $b = 2; $a = $b += 3; // $a = ($b += 3) -> $a = 5, $b = 5 ?> Undefined order of evaluation Operator precedence and associativity only determine how expressions are grouped, they do not specify an order of evaluation. PHP does not (in the general

Objects

Examples: To create a new object, use the new statement to instantiate a class: <?php class foo {     function do_foo()     {         echo "Doing foo.";      } } $bar = new foo; $bar->do_foo(); ?> If an object is converted to an object, it is not modified. If a value of any other type is converted to an object, a new instance of the stdClass built-in class is created. If the value was NULL, the new instance will be empty. An ar

Resources

NULL

Examples: There is only one value of type null, and that is the case-insensitive constant NULL. <?php $var = NULL;        ?>

Callbacks / Callables

Examples: Callback function examples A PHP function is passed by its name as a string. Any built-in or user-defined function can be used, except language constructs such as: array(), echo, empty(), eval(), exit(), isset(), list(), print or unset(). A method of an instantiated object is passed as an array containing an object at index 0 and the method name at index 1. Accessing protected and private methods from within a class is allowed. Static class methods can al