Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mozart vs PHP Scoper, and Autoloader behavior question #94

Open
Luc45 opened this issue Nov 30, 2020 · 2 comments
Open

Mozart vs PHP Scoper, and Autoloader behavior question #94

Luc45 opened this issue Nov 30, 2020 · 2 comments

Comments

@Luc45
Copy link

Luc45 commented Nov 30, 2020

Howdy!

I need to prefix the Composer dependencies of a WordPress plugin, I've been studying the differences between Mozart and PHP Scoper and trying to find out what's best for me.

I see that WooCommerce will be using Mozart on their next releases, while Yoast and Google Site Kit are using PHP Scoper.

PHP Scoper is a tool focused on Phars, therefore it doesn't seem to be able to handle Composer Autoloader gracefully.

Yoast implementation of PHP-Scoper
Prefixes the vendor libraries, remove them from composer.json and run composer dump-autoload. Then it implements their own spl_autoload_register to autoload the prefixed libraries.

Google Site Kit implementation of PHP-Scoper
Seems to drop Composer Autoloader entirely, implementing their own spl_autoload_register.

I don't like to add spl_autoload_register because it adds a file read for every class lookup, and disks are the slowest thing in computing.

I understand that Mozart is designed to work alongside Composer, using the Composer Autoloader itself. Is that correct?

Would you recommend Mozart or PHP Scoper for prefixing a WordPress plugin? Why? I saw that you (Coen Jacobs) had written an article about this subject on your blog, but the link is dead.

Thanks for your time, for this library, and for sharing your knowledge.

@Luc45
Copy link
Author

Luc45 commented Nov 30, 2020

Found the blog article with the dead link: https://coenjacobs.me/2019/07/05/why-i-felt-there-was-a-need-for-mozart/

@coenjacobs
Copy link
Owner

Obviously, I prefer Mozart for WordPress projects. I know about the other implementations and in #96 (including some more information, which was once published on my now dead blog) I have explained some of the philosophy and choices behind Mozart. Fun fact, PHP-Scoper didn't even exist back when I started Mozart. That obviously doesn't mean that you should or shouldn't use it, but that's one of the main reasons Mozart now exists.

On the topic of autoloading, yes I do believe that Mozart has a unique approach here. Mozart relies on doing as little as possible. In practice, this means that Mozart doesn't change the way Composer is autoloading anything and thus the default autoloader, provided by Composer is used in your project, after Mozart is done transforming the files.

szepeviktor pushed a commit to szepeviktor/BrianHenryIE_mozart that referenced this issue Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants