PHP 8: Making the Choice Between “switch” and “match”

In the constantly changing landscape of PHP, version 8 brought with it an innovative feature: the match expression in contrast to switch. Many see it as a streamlined and more effective counterpart to the traditional switch. Let’s explore their distinctions. The traditional switch goes something like this: With PHP 8, the equivalent match looks far … read more …

Embracing Immutability: The Theory Behind Readonly Classes

As the code base of a project grows larger and larger, maintainability, predictability and “clean code” is getting more and more a key strategy for successful projects. While it is totally ok to have “quick and dirty” smelling code for prototypes and MVP’s, things change dramatically for scaling projects in production. In this blog post, … read more …

Towards Powerful PHP Applications: WeakMaps and Their Practical Usage

PHP introduces WeakMap datastructure with version 8.0. This new data structures is capable of containing objects while simultaneously enabling them to be cleared via garbage collection once not needed anymore. WeakMap is a evolution of weak references added with PHP 7.4 and enables the development of collections of references that can be subjected to garbage … read more …

Understanding PHP’s Shift: Migrating from Resources to Objects

As said many times before, PHP is evolving from a script kiddy language to a modern and powerful object oriented one. This is not only visible with the features as enums, metadata or fibers added to PHP core, but also with things “under the hood” like migrating from resources to objects. Resources in PHP: Definition … read more …

How and When to Use PHP’s Pure Intersection Types

In this publication of my PHP related blog series, I want to address Pure Intersection Types in PHP. In the previous blogs of the series, I addressed different features added to PHP with PHP 8 and PHP 8.1. The first blog was about readonly properties, the second one focused on Enums and the third and … read more …

PHP Fibers: What They Are and Where To Use

PHP is evolving from a script kiddy programming language that has it’s focus on generating some HTML on server side to a powerful and modern programming language. Whereas PHP rendered “dynamic” websites for Web2.0 and send it to the client to display it in the browser, however, modern approaches got away from it. This is … read more …

Do Readonly Properties replace Getters (in PHP)?

I am in programming since around 2006 and started coding with Borland C++ (I can hear you saying “Bor -what”). Back that time, we created Desktop UI applications with object oriented C++ and together with the language, we learned best practices and common approaches (to object oriented programming). One major rule of thumb – among … read more …

About Mocking in Unit Tests

Recently at SCAYLE, I wrote a Laravel service that inserts data using Eloquent into a table like this: For people not familiar with Laravel/Eloquent: The HelloWorld model mirrors the database structure and the save method persists data into the database table. So far, so good. Like for any good and responsible project, I wrote unit … read more …