In October 2020 we launched our one-of-a-kind PHP prefixing service called PHP-Prefixer. It’s a new, innovative, and revolutionary way to prefix Composer dependencies. The service is a game-changer as it’s an easy way to design solutions to some of your most complicated PHP coding problems.
Another tool that prefixes Composer dependencies is the PHP-Scoper, an open-source package designed to run code modification.
If both prefixes Composer dependencies, how are the two different from each other?
When compared with PHP-scoper, PHP-Prefixer has some interesting differences that I will discuss in this post.
Addressing Shortcomings of Composer
Undoubtedly, Composer is the ABC of PHP. If you’ve been in the PHP world for a while, Composer would be your go-to method for managing dependencies for all the right reasons.
Composer has its shortcomings, and without addressing them, a PHP developer like you may have to reinvent the wheel – write everything from scratch!
Before going in-depth into a PHP-Prefixer and PHP-scoper, let’s understand one of the most significant shortcomings of Composer with a real-world scenario.
A WordPress site uses two different plugins:
- Plugin A
- Plugin B
Both use the same dependency, but Plugin A requires version v2.1, whereas Plugin B requires version v3.2. In such a situation, you may encounter a race condition. This implies that you’re entirely unaware of the sequence in which the Composer will load the dependency, and it could be the difference between bad and good coding.
Addressing these issues improves the time to market your biggest idea. While manually fixing the conflicts isn’t the solution for obvious reasons, two services address the namespace or plugin version conflicts – PHP-Prefixer and PHP-Scoper.
Let’s first understand these two services.
PHP-Scoper: The Open-Source Command Line
PHP-Scoper is an open-source command line, which provides PHP developers with the ability to run the code modification. The tool ensures that a project’s code is saved in distinct PHP namespaces.
PHP-Scoper prefixes the code ‘searching & replacing’ text patterns. The command line is based on the Symfony Finder component. This component is also used in the popular utility PHP-CS-Fixer, a tool to automatically fix PHP Coding Standards issues. PHP-Scoper goes one step further to run “patchers” on matching strings.
PHP-Prefixer: The Online Service
PHP-Prefixer is a fully-online service that applies prefixes to Composer dependencies, powered by a complex rule-based system. The service overcomes namespace conflicts and library versions conflicts in PHP.
PHP-Prefixer works by ‘understanding and parsing the PHP files.’ It then replaces what is necessary automatically.
You only have to declare what to prefix, and the service does it for you.
PHP-Scoper vs PHP-Prefixer: Comparison Table
|Method of prefixing||Parses and understands (syntaxis/semantic) the PHP files. It then automatically replaces what is necessary.||Does ‘search & replace’ of defined text patterns.|
|Type of software||Software as a service||Command-line|
|Local installation||Cloud-based service. No local installation.||Required|
|PHAR||No PHARs||Required to be installed|
|Prefixing of WordPress Plugin||Yes||Requires advanced configuration|
|Autoloading of Composer after Prefixing||Yes. The prefixed project is also a Composer project.||No|
|Customer Support||Full customer support||Community support|
|Cost||Subscription / Pay As You Go||Free (excluding the cost to manage it)|
This article is the first part of a series about PHP-Prefixer vs PHP-Scoper differences; I gave a sneak-peak of major differences between the two prefixing services. In the coming weeks, I will provide an in-depth analysis of both services and explain why and how one service compares to the former command line.
Watch out this space for more updates!
Photo by Markus Spiske on Unsplash