PHP 7.4 preview – typed properties, arrow functions, spread in arrays, preloading
PHP 7.4 arrives in November 2019 and brings several changes that will have a real impact on everyday code. Typed properties are the headline feature – at last we can declare types directly on class properties. Plus arrow functions, spread in arrays, and the null coalescing assignment operator.
- Published in PHP
Decorator pattern in PHP – composition over inheritance, cached repository example
Inheritance is the simplest way to extend a class – but not always the best. When you want to add several independent features to an object, a class hierarchy quickly becomes unreadable. Decorator lets you wrap objects in layers of functionality without modifying the original and without deep inheritance.
- Published in Wzorce projektowe
DI in Magento 2 – container, Virtual Types, Factory, shared/non-shared
Dependency Injection in Magento 2 looks like magic at first. You type an interface in the constructor and Magento delivers the right implementation. How does it know what to inject? How does DI compilation work? What are virtual types and what are they for? I break it all down.
- Published in Magento / Adobe Commerce
PHP typing in 7.x, strict_types, PHPStan, preparing for PHP 7.4
PHP’s type system evolved gradually from 5.x. PHP 7.x strengthened it significantly – parameter typing, return types, nullable types, and union types on the horizon. PHP 7.4 adds typed properties. A good moment to summarise the state of typing and show best practices worth adopting today.
- Published in PHP
