Work In Progress

This book is currently work in progress. Some sections are not yet written. Thank you for your understanding!

DON'T: Include duplicate copies of libraries shipped with Joomla itself

A few weeks ago I was troubleshooting a client's Joomla 3 site and I noticed that there were six extensions which in total included four copies of TCPDF, six copies of SimplePie and four copies of PHPMailer. All these libraries are already shipped with Joomla itself.

Do NOT include copies of libraries already included in Joomla with your software. If you absolutely have to —because you need a newer version than what Joomla provides— DO NOT USE THE SAME NAMESPACE AND CLASS NAMES. It will break Joomla or third party extensions when your code is loaded.

In fact, even if you are including third libraries which are not included in Joomla you should be doing one of the following:

  • Do NOT load third party libraries except in a component's model which is never going to be used outside of your component.

  • Change the namespace of your third party libraries using Rector.

The first method is not a fool-proof way to go about it. The third party library you are using may be included in Joomla or a different third party extension (worst case scenario: a system plugin which always loads this library) therefore causing your own code to break. This happened to me when I contributed the WebAuthn code to Joomla 4, thereby breaking my Login with Apple plugin which was using a newer version of one of the libraries used by the WebAuthn code. Oops.

Changing the namespace of your dependencies with Rector is fairly trivial and guarantees that any third party libraries you include in your code will neither interfere with core or third party code, nor will they be interfered with by core or third party code. It's one more (small and simple) step building your extensions but it can make a massively positive difference to your clients who construct their sites out of prepackaged, mass-distributed code they can't (and usually don't even know how to) modify.