PHP: Guides and Practical Know-how | Page 29 | mironsoft Blog
PHP
-
Feb 14, 2025
When the same authorization check gets copied into twenty resolvers, that's a sign the behavior belongs in the schema declaration instead of repeated code. GraphQL directives make exactly that possible: an @auth tag on a field replaces the boilerplate check, a @formatDate directive controls output formats without touching the resolver.
-
-
Feb 11, 2025
An assignment like $b = $a for a large PHP array looks at first glance like an expensive copy operation, but internally it initially only costs incrementing a reference counter. Copy-on-Write postpones the actual copy to the moment one of the two variables is actually modified, and this exact mechanism decides memory usage and performance for every array hand off in PHP.
-
Feb 10, 2025
Mocking everything a class touches, indiscriminately, produces unit tests that break on every refactor even though the application's behavior never changed. Gerard Meszaros' taxonomy distinguishes dummy, stub, fake, spy and mock as five clearly separated roles, each with a different purpose, a different verification logic and a different degree of coupling to implementation details. This article walks through the theory behind every test double using hand-written PHP implementations, independent of any particular testing framework.
-
Feb 9, 2025
Duplicated test data in every setUp, magic arrays in DataProviders, and hardcoded IDs scattered across hundreds of test classes. These are the typical signs of a test suite without a clear data organization strategy. The Builder pattern, fixture classes and factory methods bring order without overengineering.
-
Feb 7, 2025
Anyone maintaining several related PHP packages knows the pain: every small change in the core package means a new version, a new tag, and a composer update in every dependent package just to test locally whether everything still fits together. A PHP monorepo with Composer path repositories solves exactly this problem, without making the later release to Packagist any harder.
-
Feb 5, 2025
Anyone hosting several client projects on one server eventually runs into different PHP version requirements, since Magento, WordPress, and legacy applications rarely demand the same version. Versioned FPM packages, update-alternatives, and cleanly separated pools per vhost let you run multiple PHP versions side by side without conflicts and safely in production.
-
Feb 4, 2025
Anyone writing Magento code without tests learns during the first refactoring how fragile the dependencies really are. PHPUnit tests for repositories, service contracts and ViewModels cover the logic of the most important layers, without needing the full Magento bootstrap.
-
Feb 1, 2025
Build-time code generation produces finished, compilable PHP code before an application even starts, instead of reading metadata via reflection again on every request. Symfony and Laravel use this technique for compiled containers, because generated code is treated by OPcache like any regular code and reflection overhead disappears entirely from the hot path.
-
Feb 1, 2025
Swoole Coroutines let PHP handle thousands of concurrent tasks efficiently without spawning threads or extra processes. Once you understand how the cooperative coroutine scheduler works, and how channels and WaitGroup synchronize results, you can use Swoole Coroutines for real concurrency in PHP without inheriting the classic pitfalls of threading.