8. WHAT DOES MODERN PHP DEVELOPMENT MEAN?
MODERN PHP CONCEPTS
▸ Namespaces
▸ Autoloading
▸ Closures (anonymous functions)
▸ *Type hints (and return type
declarations)
▸ Late static binding
▸ Traits
▸ Generators
▸ Group aliasing
▸ *Exception-based error
handling
▸ libsodium and modern security
28. BEST PRACTICES
WHY USE NAMESPACES?
▸ Prevent naming collisions
▸ Code readability
▸ Promote better code organization
▸ Aliasing can help marry legacy with modern code
36. BEST PRACTICES
AUTOLOADING
▸ Automatic loading of classes etc. instead of manually requiring them
▸ Typically follows project organization
▸ Composer vs PSR-0 vs PSR-4 vs Rolling your own
43. WORDPRESS DEVELOPMENT IN A MODERN PHP WORLD
TYPE HINTS
▸ Helps catch avoidable mistakes
▸ Defines expectations for what is accepted
▸ *Base support for class/interface name or self
▸ 5.1 added array, 5.4 added callable
▸ 7.0 added scalar type support,
e.g. string, bool, int, float (no aliases!)
▸ 7.1 added iterable, 7.2 added object
▸ Multiple types not supported
44. TYPE HINTS
EXAMPLES
▸ function feed_pet( Pet $pet )
▸ ex_update_collection( Collection $collection, array $atts );
▸ try {} catch( Marker_Interface $exception ) {}
57. NICE TO HAVES
LATE STATIC BINDING (5.3+)
▸ Allows parent/super classes to statically reference aspects
of the calling or sub-class
▸ Flips the OOP inheritance model on its head
▸ Leveraged via the static keyword vs self
61. NICE TO HAVES
TRAITS (5.4+)
▸ Makes reusing code across classes simpler
▸ Free of inheritance (horizontal use)
▸ Traits vs dependency injection
▸ Really powerful when combined with abstract methods
▸ Are traits really evil? (no)
66. NICE TO HAVES
GROUP ALIASING (7+)
▸ Allows for aliasing multiple classes or functions at once
▸ Cuts down on top-heavy aliasing blocks
▸ Importing and aliasing functions, importing constants was added in 5.6