title: make a PHP script executable from CLI and include-able?
body: <p>Consider this:</p>
  
  <pre class="lang-php prettyprint-override"><code>#!/usr/bin/php
  &lt;?php
  class Foo {
          static function bar () {
                  echo "Foo-&gt;bar\n";
          }
  }
  if (PHP_SAPI === 'cli') {
          Foo::bar();
  }
  ?&gt;
  </code></pre>
  
  <p>I can execute this from CLI, but when I <code>include</code> it in, say, a CGI-run PHP script, the shebang ends up in the output.</p>
  
  <p>I like simple scripts <em>compact</em>: I guess I could put the <code>class</code> part in a separate "lib"-file and have a simple wrapper for CLI use. BUT I'd like to keep it all in one place without having to worry about include paths etc.</p>
  
  <p>Is this possible without <code>ob_*</code>-wrapping the <code>include</code> to capture the shebang (if this is even possible), or is it dumb to cram all of this into one file anyway? Alternatives/Thoughts/Best Practices welcome!</p>
  
  <p>Edit: I'd like to put the script in my <code>PATH</code>, so calling I'd rather not call it by <code>php file.php</code>. See my comment to @misplacedme's answer</p>