title: PHP zip_open() and php://temp, can't seem to open
body: <p>Not sure if this is possible, but it's become an academic struggle now.</p>
  
  <p>Using the <code>__halt_compiler()</code> trick to embed binary data in a PHP file, I've successfully created a self-opening script which will <code>fseek()</code> to <code>__COMPILER_HALT_OFFSET__</code> (<em>not too hard seeing as this precise example is documented in the manual</em>)</p>
  
  <p>Anyways, I've stored a small lump of binary ZIP data (<em>a single folder containing a single file that says "hello world"</em>) after my call to <code>__halt_compiler()</code></p>
  
  <p>What I've tried to do is copy the data directly to the <code>php://temp</code> stream, and have done so with success (<em>if I <code>rewind()</code> and <code>passthru()</code> the temporary stream handle, it dumps the data</em>)</p>
  
  <pre><code>$php = fopen(__FILE__, 'rb');
  $tmp = fopen('php://temp', 'r+b');
  fseek($php, __COMPILER_HALT_OFFSET__);
  stream_copy_to_stream($php, $tmp);
  </code></pre>
  
  <p>My problem comes with trying to now open <code>php://temp</code><sup>1</sup> with <code>zip_open()</code></p>
  
  <pre><code>$zip = zip_open('php://temp');
  </code></pre>
  
  <blockquote>
    <p><sup>1</sup>From what I can see (<em>despite other such possibilities as lack of stream support with <code>zip_open()</code></em>) the problem here is the inherent non-permanence of data in <code>php://memory</code> and <code>php://temp</code> streams between handles. If this can be worked around, perhaps it is in fact possible.</p>
  </blockquote>
  
  <p>It keeps kicking back error code <code>11</code>, which I have found <strong>no</strong><sup>2</sup> documentation on (<em>seemingly, like most other possible error codes</em>)</p>
  
  <pre><code>var_dump($zip); // int(11)
  </code></pre>
  
  <blockquote>
    <p><sup>2</sup> As @cweiske pointed out, error code <code>11 = ZipArchive::ER_OPEN</code>, <em>Can't open file</em></p>
  </blockquote>
  
  <p>Is this consequence to my attempt at using the <code>php://temp</code> stream, or some other possible issue? I'm also aware there exists an OOP approach (<em><code>ZipArchive</code>, et al.</em>) but I figured I'd start with the basics.</p>
  
  <p>Any ideas?</p>