- Open and Close tags.
- Open tag standard
<?php
- Open tag short
<?
- Tag for values
<?=
- Close tag optional
- Open tag standard
- Types
- Booleans
- Integers numbers (GMP mainly)
- Float point numbers
- Strings
- Single quoted (only text)
- Double quoted (interpolated)
- Heredoc (interpolated)
- Nowdoc (only text)
- Arrays
- Old format (
array()
) - Optional indexing
- Mix string and integer indexes
- Auto-index adding elements
- New format (PHP 5.4+,
[]
) - Array dereferencing (PHP 5.4+)
- Old format (
- Iterables
- Foreach iteration
- Parameter type (for functions arguments)
- Return type (for functions return data)
- Iterator generator (
yield
) - Iterable type variance (broaden methods using array)
- Objects
- Initialization
- Converting to object (casting)
- Resources
- NULL (internally handled by
undefined
) - Callable / Callbacks
- Callable as strings (function names)
- Callable as arrays (object or class and method names)
- Pseudo-types
- Mixed
- Number
- Callable
- Array/Object
- void
- so on (
$...
)
- Type juggling
- Type casting
- Variables
- Predefined variables (superglobals)
- Variable scope
-
global
: functions, classes and objects -
static
: functions and classes - References
global
+static
-
- Variable variables
- Variables from external sources
-
$_GET
,$_POST
- Magic Quotes
- Image submit
- HTTP Cookies
- Variable types (
is_array
,gettype
, ...)
-
- Constants
- Syntax
- Magic Constants (
__FILE__
,__LINE__
,__DIR__
, ...)
- Expressions
- Assignment
- Pre/Post-Increment/Decrement
- Comparison evaluations
- Mathematic evaluations
- Short operations with assignment
- Ternary operator
- Operators
- Precedence (see table below)
- Arithmetic operators
- Assignment operators
- Basic assignment
- Assignment operators
- Assignment by reference
- Bitwise operators
- Comparison operators
- Comparison operators
- Ternary operator
- Null coalesce operator
- Error control operator
- Execution operator (backticks)
- Incrementing/Decrementing operators
- Logical operators
- String operator (concat)
- Array operators (union, equality, identity, ...)
- Type operator (
instanceof
)
- Control Structures
- Alternative syntax for control structures (with
end...
instead of curly-braces) -
if
-
else
-
elseif
orelse if
-
while
-
do
...while
-
for
-
foreach
-
break
-
continue
-
switch
-
declare
-
return
-
require
andrequire_once
-
include
andinclude_once
-
goto
- Alternative syntax for control structures (with
- Functions
- User defined functions
- Conditional functions
- Functions within functions
- Recursive functions
- Function arguments
- Normal arguments
- Reference arguments
- Default arguments
- Type declarations
- Variable length argument lists
- Variable provide arguments
- Returning values
- Use of
return
- Return reference
- Return type declarations
- Nullable return type declaration
- Use of
- Variable functions
- Variable function/method
- Variable static method
- Complex callables
- Anonymous functions
- Closure class
-
use
-
use
passing by reference - Automatic binding of
$this
- Static anonymous functions
- User defined functions
- Classes and Objects
- Class definition
-
new
and creation of objects - Methods and use of
$this
pseudo-variable - Assignment of objects always using references
- Class methods
- Access to the object elements (
->
) - Use of
::class
to obtain the class name - Properties (attributes)
- Class constants
- Autoloading classes (SPL)
- Constructors and destructors
- Visibility (
public
,private
andprotected
)- Properties
- Methods
- Constants
- Inheritance of classes (
extends
) - Scope resolution of operator
::
static
keyword-
static
to create new objects inside of class methods - Static variables for objects
- Static variables for methods
- Late state bindings
-
- Abstract Classes (
abstract
) - Interfaces (
implements
) - Traits (
trait
) - Anonymous classes
- Overloading
-
__call
for method overloading -
__callStatic
for class method overloading -
__get
,__set
,__unset
and__isset
for properties overloading - Object iteration (using
Iterator
forforeach
) - Magic methods:
__sleep
,__wakeup
,__set_state
,__clone
,__debugInfo
- Magic method:
__toString
- Magic method:
__invoke
(callable) -
final
to avoid overloading of a method during inheritance - Cloning (
clone
and__clone
) - Comparing objects (
==
and===
) - Type hinting
- Late state binding
- Object serialization (
serialize
andunserialize
)
-
- Namespaces
- Syntax
- Declaring simple namespaces
- Declare subnamespaces
- Multiple namespaces in a file
- Using namespaces
- Dynamic calling methods
- Use namespaces and
__NAMESPACE__
constant - Aliasing (
use
,use const
anduse function
) - Global namespace (
\
) - Fallback to the global namespace
- Name Resolution Rules
- Handling errors
- Exceptions
-
try...catch...finally
- Throw custom Exceptions (inherited)
-
- Generators (functions in
foreach
and use ofyield
) - References
- Assigning by reference
- Passing by reference
- Returning by reference
- Predefined variables
- Superglobals
-
$GLOBALS
-
$_SERVER
,$_ENV
-
$_GET
,$_POST
,$_REQUEST
,$_FILES
,$_COOKIE
,$HTTP_POST_RAW_DATA
-
$_SESSION
-
$php_errormsg
-
$argc
,$argv
- Predefined Exceptions
- Exception
- ErrorException
- Error
- ArgumentCountError
- ArithmeticError
- AssertionError
- DivisionByZeroError
- CompileError
- ParseError
- TypeError
- Predefined Interfaces and Classes
- Traversable
- Iterator
- IteratorAggregate
- Throwable
- ArrayAccess
- Serializable
- Closure
- Generator
- WeakReference
- Context options and parameters
- Socket context options
- HTTP context options
- FTP context options
- SSL context options
- CURL context options
- Phar context options
- MongoDB context options
- Context parameters
- Zip context options
- Supported Protocols and Wrappers
- file://
- http://
- ftp://
- php://
- zlib://
- data://
- glob://
- phar://
- ssh2://
- rar://
- ogg://
- expect://
Associativity | Operators | Additional Information |
---|---|---|
non-associative | clone new | clone and new |
right | ** | arithmetic |
right | ++ -- ~ (int) (float) (string) (array) (object) (bool) @ | types and increment/decrement |
non-associative | instanceof | types |
right | ! | logical |
left | * / % | arithmetic |
left | + - . | arithmetic and string |
left | << >> | bitwise |
non-associative | < <= > >= | comparison |
non-associative | == != === !== <> <=> | comparison |
left | & | bitwise and references |
left | ^ | bitwise |
left | ||
left | && | logical |
left | ||
right | ?? | null coalescing |
left | ? : | ternary |
right | = += -= *= **= /= .= %= &= |= ^= <<= >>= | assignment |
right | yield from | yield from |
right | yield | yield |
left | and | logical |
left | xor | logical |
left | or | logical |
You can check here the main issues (or incompatibilities) with PHP.