Filtering Empty Arrays Before array_merge()? Picture this: you’re looping through something, calling a function each time. It always returns an array, and, sometimes it gives back an empty array. At the end, all these array will be array_merge(…$results) together. The first point is to avoid array_merge() inside the loop, as it is one of the […]
Testing regex with reverse generation I had a regex once that passed 37 hand-written tests. First fuzz run found a crash in 200ms. That’s what this post is about: testing regex with reverse generation using pointybeard/reverse-regex to generate strings guaranteed to match a regex, so you can test your validation code against inputs you didn’t […]
The Empty String in PHP: One Value, Too Many Jobs The humble empty string “” is everywhere. It’s the quiet default, the silent failure signal or the silent success signal, the lazy cast, the natural accumulator. Behind the obvious simplicity of the empty string in PHP lies a surprising amount of overloaded meanings, which leads […]
strpos() Syndrom: When 0 And false Are Not The Same In PHP, several functions can return 0 or false or even null, and all these values may be confused for different things. The most popular function with this syndrom is strpos(), hence the name of this classic PHP bug. strpos() returns the position where the […]
Usages of PHP Static variables I thought static variables were a lesser known PHP feature. Then, I counted about 30% of PHP projects using it, and I realized it was a more common feature than I thought. If you haven’t encountered then, they are distinct from static properties. Within a method, it is possible to […]
The Art of Being Anonymous in PHP This post is a tour of PHP’s nameless constructs: from closures and arrow functions to anonymous classes and non-binding catch blocks. Every day, in most PHP code, things have names. Variables are named, classes have identifiers, functions are called by their name. Though, PHP also offers a rich […]
Renaming Parameters in a method Renaming parameters in a method used to be an innocuous operation: one could do it without impact. Since PHP 8.0, such renaming may break existing calls. With named parameters, not only the method name, but also its parameters are part of the call. And it is a common challenge to […]
PHP Inheritance Challenge: Calling All Ancestors PHP’s object-oriented features are exhaustive and modern, yet sometimes life send you a little challenge: who doesn’t like a surprise? Today we’ll look at a rare inheritance puzzle. In this post, we are calling all ancestors in a class hierarchy. We start with three classes, extending each other in […]
Refactoring Strings to Enums This article describes the journey of refactoring a not-so-old piece of code from using strings to using enumerations. Original Reasons When Exakat was started in 2014, enumerations were not even on the radar. Strings, and sometimes constants, were the obvious solution. As the original concept evolved quickly, strings were used everywhere, […]
All PHP 8.5 hash algorithms Choosing the right hashing algorithm is difficult, balancing the need for security, speed, and reliability. PHP offers a almost 60 built-in hashing options, but not all are created equal : some are industry standards for cryptographic security, while others are optimized for lightning-fast non-cryptographic tasks like caching or checksums; some […]
Convert a string to integer with PHP PHP 8.5 provides a new error message when one tries to convert a string to integer with PHP. The float-string “%s” is not representable as an int, cast occurred This is new with this version, and besides the warning itself, it is not even a changed behavior. It […]











