Object-oriented and modern PHP
The object model in one run: classes and objects, the constructor, inheritance, interfaces and traits, enums, the magic methods and attributes, exceptions, strict_types, closures and generators. The PHP OOP section holds the longer examples of the same ground.
031
Classes and objects
define a class, create objects, add methods, and what $this is
Open
032
Constructors and promotion
__construct, constructor promotion, defaults and readonly properties
Open
033
Inheritance
extends, parent calls, visibility and abstract classes
Open
034
Interfaces and traits
interfaces, implements, traits, and when to use each one
Open
035
Enums
enums, backed enums, methods on an enum, and match over one
Open
036
Magic methods
__toString, __invoke, __get and __set, and when they earn their place
Open
037
Attributes
add metadata with attributes and read it back with reflection
Open
038
Exceptions
throw, catch by type, and clean up with finally
Open
039
Strict types
strict_types and the exact scalar and return types it enforces
Open
040
Closures and arrow functions
anonymous functions, captured scope, and a callable passed in
Open
041
Generators with yield
yield a large sequence without loading an array into memory
Open