PHP.lab 🐘
A curated knowledge base and laboratory for PHP engineering.
Index
Description
- What is PHP?
- PHP history
- PHP features
- PHP code
- Literals, constants, variables
- Literals
- Constants
- Variables
- References
- Types
- Type system
- Type declarations
- Type juggling
- Expressions
- Operators
- Operator precedence
- Arithmetic operators
- Logical operators
- Bitwise operators
- Comparison operators
- Increment & decrement operators
- Assignment operators
- String operators
- Array operators
- Type operators
- Functional operator
- Execution operators
- Error control operators
- Control flow
if conditional statement
if-else conditional statement
if-elseif-else conditional statement
switch conditional statement
match conditional statement
while loop statement
do-while loop statement
for loop statement
foreach loop statement
break instruction
continue instruction
goto instruction
- Built-in types
- Special
- Null
- Resources
- Scalar
- Booleans
- Integers
- Floating point
- Strings
- Compound
- Arrays
- Objects
- Enumerations
- Functions
- Functions
- Anonymous functions
- First class callable syntax
- Generators
- Fibers
- Classes, interfaces, traits
- Classes
- Classes
- Class members
- Magic methods
- Constructors and destructors
- Objects
- Inheritance
- Anonymous classes
- Autoloading classes
- Abstract classes
- Interfaces
- Traits
- Errors and exceptions
- Errors
- Exceptions
- Attributes
- Reflections
- Namespaces
Examples
- PHP features
- Loosely typed language
- Dynamically typed language
- PHP code
- Literals, constants, variables
- Literals
- Constants
- Defining constants
- Types in constant definitions
- Expressions in constant definitions
- Accessing constants
- Scope of the constants
- Functions handling constants
define function
defined function
constant function
get_defined_constants function
- Variables
- Defining variables
- Types in variable definitions
- Accessing variables
- Assigning to the variables
- Destroying variables
- Scope of the variables
- Global variables
- Global variable in an included file
- Variable from a file included within a function
- Variable binding to a closure
- Static variables
- Static variables and an inheritance
- Functions handling variables
isset function
unset function
get_defined_vars function
- Types
- Types of the function arguments
- Types of the function return
- Strict type control
- Functions handling types
gettype function
settype function
- Operators
- Arithmetic operators
- Modulo operator
- Increment & decrement operators
- Assignment operators
- Basic assignment operator
- Null coalescing assignment operator
- Assignment expression value
- Bitwise operators
- Bitwise shift operators and conversions
- Comparison operators
- Strict equality & inequality operators
- Three-way comparison (spaceship) operator
- Ternary operator
- Ternary operator shorthand
- Ternary operator and conversions
- Nested ternary operators
- Spaceship operator
- Null coalescing operator
- Null coalescing operator and conversions
- Nested null coalescing operator
- Logical operators
- Type operator conversions
- Nullsafe operator
- Control flow
if conditional statements
if conditional statement
if alternative syntax
if formatting
if-else conditional statement
if-else alternative syntax
if-else formatting
if-elseif-else conditional statement
if-elseif-else alternative syntax
switch conditional statement
switch conditional statement
switch alternative syntax
match conditional statement
while loop statements
while loop statement
while formatting
do-while loop statement
do-while formatting
for loop statement
for loop statement
for alternative syntax
for formatting
- ‘foreach` loop statement
- ‘foreach` loop statement
- ‘foreach` alternative syntax
- ‘foreach` formatting
break instruction
continue instruction
goto instruction
- Built-in types
- Special
- Null
- Null
- Null syntax
- Null use cases
- Undefined value
- Database query with no result
- Testing for null
- Null as unset effect
- Casting from null
- Resource
- Resource
- Checking resource type
- Scalar
- Booleans
- Bool
- Bool syntax
- Bool use cases
- Comparison result
- Control structures
- Testing for bool
- Logical context
- Logical context and equal operator
- Casting to bool
- Casting from bool
- Automatic conversions to bool
- Integers
- Int
- Int syntax
- Int use cases
- Quantity
- Index
- Testing for int
- Binary, octal, decimal and hexagonal integer notation
- Int values range
- Casting to int
- Casting from int
- Floating point
- Float
- Float syntax
- Float exponential notation
- Float use cases
- Measure
- Calculation
- Testing for float
- Float values range
- NaN
- Infinity
- Casting to float
- Casting from float
- Strings
- String
- String syntax
- Escape sequences
- String use cases
- Text processing
- Text statistics
- Testing for string
- String interpolation
- Basic types formating in strings
- String length and word count
- Numeric strings
- String concatenation
- String trimming
- String cases
- Casting to string
- Casting from string
- Compound
- Arrays
- Array
- Array syntax
- Array definition and initialisation
- Array assignment and overwriting
- Array creating
- Array displaying
- Array modifying
- Array destroying
- Array values
- Array keys
- Array key type casting and overwriting
- Array elements
- Array element appending with array access operator
- Array elements creating
- Array elements accessing
- Array elements modifying
- Array elements destroying
- Indexed arrays
- Associative arrays
- Nested arrays
- Testing for array
- Array destructuring
- Array unpacking
- Array unpacking and key overwriting
- Array merging
- Array merging and key overwriting
- Array adding
- Array adding and key overwriting
- Array combining
- Array comparing
- Array sorting
- Array size
- Array internal pointer
- Iterating over array_and_reading elements
- Iterating over array and updating elements
- Passing array to the function
- Casting to array
- Casting from array
- Objects
- Object
- Object definition and initialisation
- Object assigning and overwriting
- Object creating
- Object displaying
- Object modifying
- Object destroying
- Object properties
- Object properties defining and initialising
- Dynamic properties
- Object properties accessing
- Object properties updating
- Testing for object
- Casting to object
- Casting from object
- Enumerations
- Enum
- Enum use cases
- Constant set of states
- Set of options in the contract
- Basic enums
- Backed enums
- Enum case values linsting
- Enum constants
- Enum methods
- Enum static methods
- Enum implementing interface
- Enum using trait
- Enum case as constant value
- Enum case in constant expression
- Casting from enum case
- Functions
- Function
- Function variations
- Functions possible formatting
- Function with function definition
- Function with class definition
- Function call before definition
- Function conditional call after conditional definition
- Function calling function
- Function global scope
- Function arguments
- Passing arguments by value
- Passing arguments by reference
- Passing arguments
- Function arguments dafault value
- Function arguments variable number
- Function named arguments
- Function returning value
- Function with static variable
- Variable function
- Anonymous function (lambda)
- Anonymous function variations
- Closure
- Closure variations
- Closure binding by value
- Closure binding by reference
- Closure binding $this
- Static anonymous function
- Arrow function
- Arrow function binding
- Function as variable
- Callbacks
- Callbacks formatting
- Higher order functions
- Generators
- Generator
- Generator yielding values
- Generator yielding key - value pairs
- Generator yielding null
- Yielding element by value
- Yielding element by reference
- Generator calling generator
- Yielding from array
- Yielding from array with keys
- Yielding from generator
- Yielding from generator with keys
- Yielding from and keys collision
- Generator returning value
- Classes, interfaces, traits
- Classes
- Classes
- Class
- Class definition
- Class instantiation
- Class instantiation from a string
- Class instantiation from an expression
- Class instantiation from static, self and parent keywords
- Class instatiation by a factory method
- Class instantiation ways
- Object assigning to the variable, passing to the function and returning by the function
- Object access
- Class instatiation and immediate instance member access
- Readonly class
- Readonly class inheritance
- Class inheritance
- Class inheritance and class name resolution
- Class inheritance and covariance, contravariance, inheritance
- Class name resolution
- Class members
- Class members
- Class static members
- Class member visibility
- Class member visibility from the same class object
- Class members static access
- Class members dynamic access
- Class member access by static, self and parent keywords
- Class constant
- Class constant visibility modifiers
- Class constant type declarations
- Class property
- Class static property
- Class property definition
- Class property definition required modifier
- Class property visibility modifiers
- Class property declaration default visibility
- Class property asymetric visibility
- Class property asymetric visibility and inheritance property redefinition
- Class property type declarations
- Nullsafe properties
- Class property access
- Class typed property initialisation before access
- Class readonly property
- Class readonly property initialisation
- Class readonly property initialisation scope
- Class readonly property initialisation during cloning
- Class readonly property visibility
- Class readonly property interior mutability
- Class dynamic property
- Class method
- Class static method
- Class method visibility modifiers
- Class method visibility and polimorphism
- Class method type declarations
- Nullsafe methods
- Property and method with the same name
- Anonymous function property and method with the same name
- Class backed property hook
- Class asymetric backed property hook
- Class backed property hook contravariance
- Class backed property hook shorthand omitted parameter type
- Class backed property hook shorthand expression
- Class backed property hook and constructor promotion
- Class virtual property hook
- Constructors and destructors
- Constructor and destructor
- Constructor
- Constructor arguments
- Constructor promotion
- Constructor promotion property modifiers
- Constructor promotion property type declarations
- Constructor and inheritance
- Private constructor
- Destructor
- Destructor and inheritance
- Objects
- Class object
- Class object definition and initialisation
- Class object modifying
- Iterating over object and reading properties
- Iterating over object and updating properties
- Class object comparing
- Class object serializing
- Class object cloning
- Class object and reference
- Lazy ghost
- Lazy proxy
- Inheritance
- Class inheritance
- Extending class
- Base and derived class
- Multilevel inheritance
- Encapsulation
- Polimorphism
- Class inheritance and members visibility
- Class members visibility modifiers
- Class constant overriding and visibility
- Class property overriding and visibility
- Class static property overriding with visibility
- Class method overriding with visibility
- Class static method overriding with visibility
- Class inheritance and method overriding
- Class property hook overriding with visibility
- Class final constant
- Class final property
- Class final method
- Class final property hook
- Class constant access with visibility
- Class final constant access with visibility
- Class property access with visibility
- Class static property access with visibility
- Class readonly property access with visibility
- Class final property access with visibility
- Class method access with visibility
- Class static method access with visibility
- Class final method access with visibility
- Class property hook access with visibility
- Class inheritance and public members access
- Class members overriding and visibility compatibility
- Class method overriding and paramenter number compatibility
- Class method overriding and paramenter requireness compatibility
- Class method overriding and types compatibility
- Class property overloading
- Class method overloading
- Final class
- Static method call
- Non-static method call
- Forwarding method call
- Non-forwarding method call
forward_static_call function
self:: vs static:: member referencing
static:: vs $this-> member referencing
- Anonymous classes
- Anonymous class
- Anonymous class with constructor
- Anonymous class extending class
- Anonymous class implementing interface
- Anonymous class using trait
- Readonly anonymous class
- Anonymouns class object class
- Anonymous class object as another class property
- Abstract classes
- Abstract class
- Abstract class without abstract members
- Abstract method
- Abstract property (hooks)
- Abstract class with abstract members
- Interfaces
- Interface
- Interface and dependency injection
- Implementing interface
- Interface constant
- Interface method
- Interface property (hooks)
- Multiple interface implementing
- Interface extending interface
- Extending class and implementing interface
- Interface implemented by abstract class
- Traits
- Trait
- Trait and reusability
- Trait members access
- Trait constant
- Trait property
- Trait static property
- Trait method
- Trait static method
- Trait abstract method
- Trait final method
- Multiple trait using
- Trait using trait
- Extending class and using trait
- Multiple trait using and conflict resolution
- Trait members visibility changing
- Errors and exceptions
- Errors
- Triggering and handling errors
- Catching errors
- Exceptions
- Exception
- Throwing an exception
- Throwing a defined exception
- Throwing an exception as an expression
- Catching an exception
- Catching a defined exception
- Catching an exception and ommiting the caught variable
- Catching exceptions of various types
- Catching an exception of multiple types
- Code always executed
try-catch-finally
- Throwing and catching an exception and returning a value
- Nesting
try-catch in try
- Nesting
try-catch in catch
- Rethrowing an exception in the catch block
- Rethrowing an exception in the catch block and throwing an exception in the finally block
- Exceptions hierarchy
- Attributes
- Attribute
- Attributes
- Attribute with argument
- Repeatable attributes
- Function attribute
- Enum attribute
- Class attribute
- Reflections
- Function reflections
- Enum reflections
- Class reflections
- Class constant reflections
- Property reflections
- Method reflections
- Built-in constructs & library
- Functions
- Language constructs
- Class parents (SPL)
- Class implements (SPL)
- Class uses (SPL)
- Object ID (SPL)
- Object hash (SPL)
- SPL classes (SPL)
- Iterators
- Iterator count (SPL)
- Iterator to array (SPL)
- Iterator apply (SPL)
- Autoloadig
- Autoload functions (SPL)
- Autoload register (SPL)
- Autoload unregister (SPL)
- Autoload (SPL)
- Autoload extensions (SPL)
- Methods
- Magic methods
- __set
- __get
- __call
- __callStatic
- __invoke
- __isset
- __unset
- __sleep
- __wakeup
- __serialize
- __unserialize
- __toString
- __debugInfo
- __construct
- __destruct
- Classes
- Language constructs
- Closure
- Generator
- Array object (SPL)
- Standard class
- Weak reference
- Sensitive parameter value
- Data structures
- Doubly linked list (SPL)
- Stack (SPL)
- Queue (SPL)
- Priority queue (SPL)
- Max heap (SPL)
- Min heap (SPL)
- Fixed array (SPL)
- Object storage (SPL)
- Weak map
- Iterators
- Array iterator (SPL)
- Recursive array iterator (SPL)
- Iterator iterator (SPL)
- Recursive iterator iterator (SPL)
- Append iterator (SPL)
- Empty iterator (SPL)
- Limit iterator (SPL)
- No rewind iterator (SPL)
- Infinite iterator (SPL)
- Multiple iterator (SPL)
- Callback filter iterator (SPL)
- Recursive callback filter iterator (SPL)
- Caching iterator (SPL)
- Recursive caching iterator (SPL)
- Regex iterator (SPL)
- Recursive regex iterator (SPL)
- Filesystem iterator (SPL)
- Directory iterator (SPL)
- Recursive directory iterator (SPL)
- Glob iterator (SPL)
- Recursive tree iterator (SPL)
- Parent iterator
- Exceptions
- Exception
- Error
- Error exception
- Type error
- Invalid argument exception (SPL)
- Value error
- Argument count error
- Unexpected value exception (SPL)
- Bad function call exception (SPL)
- Bad method call exception (SPL)
- Arithmetic error
- Division by zero error
- Unhandled match error
- Assertion error
- Closed generator exception
- Logic exception (SPL)
- Length exception (SPL)
- Out of bounds exception (SPL)
- Out of range exception (SPL)
- Overflow exception (SPL)
- Underflow exception (SPL)
- Range exception (SPL)
- Domain exception (SPL)
- Runtime exception (SPL)
- Parse error
- Files
- File info (SPL)
- File object (SPL)
- Interfaces
- Data
- Stringable
- Serializable
- Collections
- Array access
- Countable (SPL)
- Iterators
- Traversable
- Iterator
- Seekable iterator (SPL)
- Iterator aggregate
- Outer iterator (SPL)
- Recursive iterator (SPL)
- Exceptions
- Throwable
- Standards
- Basic coding standard (PSR-1)
- Extended coding style (PSR-12)
- PER Coding Style 3.0
- Autoloading standard (PSR-4)
- Logger interface (PSR-3)
- Simple cache (PSR-16)
- Caching interface (PSR-6)
License
This project is licensed under the GPL-3.0 - see LICENSE.md.