Move that foreach() inside the method Several PHP functions work with single or multiple values. For example, array_merge(), which merges several arrays into one. Or, isset(), which checks simultaneously the existence of several variables. str_replace() and preg_replace_callback() also come to mind. This is a good place to move that foreach() inside the method. This approach […]
PDFF : PHP Document File Format PDFF, or internally named PHP Document File Format, has been at the center of the development of Exakat since late 2021. It comes from a specific problem : describing dependencies, for the static analysis engine to understand and to take advantage of them, without auditing their source at the […]
Literal candidates for constants Literals are hard coded values in the source. Once they are written, they can’t be changed without altering the source code. This is always fine, initially, while building the first implementations. Yet, later, it may arise that such literal have to be managed from different points of the code. This is […]
Interfaces are not class templates Interfaces are an important part of OOP, in PHP as in other OOP languages. According to the manual, “Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are implemented.” Besides interfaces, PHP also supports abstract classes, which […]
One less hidden bug with Enum PHP 8.1 provides now enumerations, a.k.a. enums, as a native PHP construct. They provide a custom type with a limited set of values. Enumerations have been around in PHP in various forms, for a long time : check bensampo/laravel-enum, spatie/enum, marc-mabe/php-enum, eloquent/enumeration or even any framework (CakePHP-enums). Before that, […]
6 unicity traps that sideline PHP code Sometimes, code is being ignored by PHP : code is painstakingly written but never gets executed. How is that even possible? May be, because it was not so painstakingly coded. Indeed, there are some PHP coding structures which natively and silently overwrites or ignore code. This leads to […]
String to number comparison with PHP 8.x @FredBouchery reported one tiny update from PHP 8.0 : some of the comparisons have been modified between PHP 7 and PHP 8. This is pretty old news, since PHP 8.0 is not even the latest and greatest version of PHP, and it is also quite benign : For […]
All the Dynamic Syntax in PHP With PHP, dynamic calls happens when the call gets at least one of its expression’s elements (and sometimes, even all of them) at execution time. They are not known at coding time, so there are usually some variables involved in the matter. Here is a review of how to […]
Speeding up array_merge() While doing a crowd review of naval battle code at @afup_rennes (in French), it appeared that the ‘no array_merge() in loops’ rule was known but not clear. Indeed, why is it that this function in particular, should be avoided in loops. Hence, this article, with a journey to memory management, coding and […]
The upgrade sandwich With PHP 8.1 released last month, it is time to learn PHP 8.1 new features, and consider upgrading PHP code to PHP 8.0 new features. Wait a second… upgrade to PHP 8.0 ? Surely you mean, 8.1. Migrating to a new PHP version Migrating to a new version is actually a simple […]