PHP: Guides and Practical Know-how | Page 25 | mironsoft Blog
PHP
-
May 12, 2025
CLI commands are often the least tested part of a PHP application. Yet these are exactly the commands that drive cron jobs, migrations, deployments and critical batch operations. The exit code is the only communication channel between a process and the calling system, and it has to be correct so CI pipelines and orchestrators can react to failures.
-
May 12, 2025
Symfony Flex Recipes automatically create configuration files, directories, and environment variables on composer require. Once you understand how manifest.json is structured and how the contrib repository works, you can build your own recipes for internal bundles and distribute them reproducibly across teams.
-
May 10, 2025
Traits are usually seen as a pure code reuse mechanism, but they can do more: a trait may declare an abstract method that every class consuming the trait is forced to implement itself. This is not a substitute for an interface, it is a distinct tool with its own rules and its own limits. This article shows how the mechanism works, where it differs from an interface, and when it actually makes sense in practice.
-
May 9, 2025
A multi-stage Dockerfile consistently separates the build environment from the runtime. Builder stages with Composer, npm and build tools hand their output forward, without ever landing in the final image themselves. The result: smaller images, less attack surface and reproducible builds for PHP and Node projects.
-
May 5, 2025
Building SQL queries through string concatenation opens one of the oldest and still one of the most dangerous vulnerability classes in web development. PDO prepared statements structurally separate code from data and rule out SQL injection regardless of what the input contains, provided they are configured correctly and applied properly to identifiers, LIKE patterns and IN lists. This article walks through the full technical implementation with PDO in PHP 8.4.
-
Apr 30, 2025
Most PHP developers only know ob_start as a workaround for the 'headers already sent' error, yet the output buffer is a full mechanism with its own stack, its own callback phases, and its own pitfalls. Understanding how PHP inserts a buffering layer between script output and the actual SAPI output lets you write template engines, wire up compression cleanly, and avoid the classic memory leaks in long-running CLI workers.
-
Apr 30, 2025
Every require, every include and every autoloader resolution in PHP goes through a path resolution step that, without a sufficiently sized realpath cache, triggers filesystem access again on every single request. In projects with thousands of classes and deep directory trees this adds up to an overhead that a few lines of configuration can almost completely eliminate.
-
Apr 28, 2025
The nullsafe operator ?-> replaces nested if-isset blocks and long && chains with a single, flat expression chain: as soon as one link in the chain is null, the entire evaluation stops immediately, without a warning, and returns null instead of throwing an exception, which makes code around deeply nested DTOs and API responses noticeably more readable.
-
Apr 25, 2025
Anyone building inheritance hierarchies in PHP with factory methods or ActiveRecord patterns inevitably runs into the difference between self:: and static::. Late Static Binding solves exactly the problem that self:: always stays bound to the class where the method was defined, instead of the class it was actually called through.
-
Apr 22, 2025
Repository tests with mocks check the wrong layer. A mock repository cannot detect a SQL syntax problem, an index problem, or an N+1 bug. Real database access in tests is expensive, but irreplaceable at the right spots. The art lies in knowing exactly where those spots are and how to implement database isolation reliably.