Working with Phar packages in PhpStorm
PHP comes with the Phar extension bundled, which allows us to put entire libraries or applications into a single “phar” file. This makes it easier to distribute our code: it’s just one file! PhpStorm can work with Phar packages in several scenarios: we can browse the contents of a Phar package, use libraries shipped as Phar packages, debug Phar packages and even run PHPUnit from a Phar package!
As an example, let’s use the PHPExcel project. This project offers us a way to work with spreadsheets and export them as Excel, ODF, PDF, … We can make use of this library by downloading it, using the PEAR package, using Composer or… using a Phar package. When we download and add the Phar package to our project, PhpStorm allows us to drill down into the package contents from our project explorer.
We can also write our code and include the Phar package using PHP’s include or require function. PhpStorm will then provide autocompletion support for all classes and functions available from the Phar package.
When setting breakpoints and running code using the debugger, we can step into code that is located inside a Phar package. Note that this only works with the XDebug debugger.
Another popular framework which ships as a Phar package is PHPUnit, the unit testing framework which is also supported by PhpStorm. From the project settings (File | Settings), we can specify how we want to load PHPUnit for running unit tests. We can do this from the include path, from an autoloader file such as Composer) or from a Phar package. PhpStorm can even download the Phar package for us.
As always, we appreciate your feedback in the comments below or in our forums!
Develop with pleasure!
– JetBrains PhpStorm Team
Subscribe to Blog updates
Thanks, we've got you!
Qodana Clone Finder: Early Access Program
In December 2020, we announced the EAP for Qodana, which is rapidly evolving into a comprehensive platform that allows companies to perform multi-level evaluations of the quality of code they own, contract, or purchase. Qodana helps you detect bugs without relying on an IDE, either on a local machi…
PhpStorm 2020.2 EAP #3
The Early Access Program for PhpStorm 2020.2 is in full swing and today we’ve got the third build of the 2020.2 EAP for you. In this blog post, you can read about improvements for Git installed in WSL2 and Search Everywhere. Download PhpStorm 2020.2 EAP (more…)…
PhpStorm 2019.3.3 Preview
We’ve just rolled out a preview for the third minor update for PhpStorm 2019.3. Please give the PhpStorm 2019.3.3 Preview build 193.6494.5 a try and share your feedback with us. (more…)…
How to Upgrade to PHP 7.4 with PhpStorm
Check out our fresh video with a few nice tips and tricks on how to update your codebase to PHP 7.4. It combines materials from the PhpStorm 2019.2 and PhpStorm 2019.3 releases, with a few cool bonuses to boot. Nikita drew our attention to the fact that setters are slower than assigning prop…