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.
Every PHP developer eventually faces the question: how to set up a local environment? For years XAMPP was the default answer. Today we have far more options – and far more reasons to move away from XAMPP to Docker-based tools. I compare three popular approaches from the perspective of working with PHP and Magento 2.
Linear search always works. You go through every element one by one and eventually find what you are looking for. The problem appears with 100,000 elements when you do this in a loop. Binary search solves that problem elegantly – but only if the data is sorted.
Observer is one of the most commonly used patterns in object-oriented programming, and in the Magento 2 ecosystem it is built into the core of the platform. If you have ever written an event observer in Magento, you have used this pattern – often without realising it.
Directly using Magento 2 models in your own code is a tempting shortcut. The model is right there, it has the method you need, it works. The problem appears when Magento is updated and the internal implementation changes. Service Contracts are Magento’s answer – a stable, public API separated from the implementation.
PHP 7.3 was officially released in December 2018. Not a revolution, but a few changes have a real impact on everyday code – especially working with JSON, more flexible Heredoc syntax, and a handful of new array functions.
For years, setting up a local Magento 2 environment was a ritual of pain: XAMPP with manual vhost configuration, fighting PHP versions, unreproducible “works on my machine” problems. DDEV solves this elegantly – Docker underneath, simple YAML configuration on top.
Sorting is a topic most of us “tick off” at university and only return to during job interviews. Yet understanding how sorting algorithms work helps make better decisions in everyday PHP and database work. I walk through a few classic approaches, implement them in PHP, and show where this has real practical relevance.
Strategy is one of those patterns that seems like unnecessary complexity on first contact. Why wrap a single algorithm in a separate class? The value only becomes clear with a second and third algorithm – when instead of a growing if-else you have clean, interchangeable code. I show how it works in PHP and where Magento 2 uses this pattern without you realising it.
One of the most common questions when working with Magento 2 is: should I override a class with a preference, or use a plugin? The answer is almost always the same – use a plugin. But “almost” does a lot of work here. I explain the differences and show when a preference makes sense.
