Comparing PHP-Scoper with PHP-Prefixer

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.

What is PHP-Prefixer vs. What is PHP-Scoper – Part I

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 prefixingParses and understands (syntaxis/semantic) the PHP files. It then automatically replaces what is necessary.Does ‘search & replace’ of defined text patterns.
Type of softwareSoftware as a serviceCommand-line
Local installationCloud-based service. No local installation. Required
PHARNo PHARsRequired to be installed
Prefixing of WordPress PluginYesRequires advanced configuration
Autoloading of Composer after PrefixingYes. The prefixed project is also a Composer project.No
Customer SupportFull customer supportCommunity support
CostSubscription / Pay As You GoFree (excluding the cost to manage it)

Wrap Up

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.