title: How to properly require a phar file
body: <p>phpunit has stopped supporting PEAR installation.  This has caused us to need to use the phar installation of phpunit moving forward.  We have a wrapping script that iterates through many directories and calls the phpunit executable on those directories.  The wrapping script then consolidates all of the generated reports into a single report.</p>
  
  <p>When phpunit was installed with PEAR, the only require we needed at the top of the wrapping script was</p>
  
  <p><code>require 'PHP/CodeCoverage/Autoload.php';</code></p>
  
  <p>Then, when the wrapping script did things like </p>
  
  <pre><code>$writer = new PHP_CodeCoverage_Report_Clover();
  $writer-&gt;process($codeCoverage, "${reportsDir}/clover-coverage.xml");
  </code></pre>
  
  <p>The autoloader would (presumably) load whatever was needed to execute this code and we'd go on our happy way.</p>
  
  <p>Since the move to a phar installation, however, things have gotten messy.  Initially I thought I could just require the phar file itself and everything would be good.</p>
  
  <p><code>require 'phpunit-3.7.31.phar';</code></p>
  
  <p>However this caused the phar file to be executed as soon as the require line was hit, aborting the wrapping script with phpunit usage output.  Since you can't use wildcards in a php require statement, I then slowly built a list of files needed to complete our wrapping script and required them like this:</p>
  
  <p><code>require 'phar://phpunit-3.7.31.phar/php-code-coverage/CodeCoverage/Report/Clover.php';</code></p>
  
  <p>This worked when I executed the wrapping script from it's directory and the phpunit.phar file was in the same directory.  However, trying to execute it from a different directory would fail saying the phar file was not found on the include path.  I attempted to change the include path, put the .phar file in locations already on the include path, and give an absolute path to the phar file in the include like:</p>
  
  <p><code>require 'phar://actual/path/to/file/phpunit-3.7.31.phar/php-code-coverage/CodeCoverage/Report/Clover.php';</code></p>
  
  <p>None of these attempts at solving my issue worked.</p>
  
  <p><strong>How do I include files from a .phar file in a way that let's me run the script from any location on my system?</strong></p>
  
  <p>Another acceptable answer would be one that lets me use the classes in the phar file without including everything I need individually.</p>
  
  <p>Ubuntu 12.04</p>
  
  <p>PHPUnit 3.7.31 (we have to stay on this version, but that doesn't really affect the question)</p>