<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="phar.setstub">
 <refnamediv>
  <refname>Phar::setStub</refname>
  <refpurpose>Used to set the PHP loader or bootstrap stub of a Phar archive</refpurpose>
 </refnamediv>
 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis role="Phar">
   <modifier>public</modifier> <type>bool</type><methodname>Phar::setStub</methodname>
   <methodparam><type class="union"><type>resource</type><type>string</type></type><parameter>stub</parameter></methodparam>
   <methodparam choice="opt"><type>int</type><parameter>length</parameter><initializer>-1</initializer></methodparam>
  </methodsynopsis>
  &phar.write;


  <para>
   This method is used to add a PHP bootstrap loader stub to a new Phar archive, or
   to replace the loader stub in an existing Phar archive.
  </para>
  <para>
   The loader stub for a Phar archive is used whenever an archive is included directly
   as in this example:
  </para>
  <programlisting role="php">
   <![CDATA[
<?php
include 'myphar.phar';
?>
   ]]>
  </programlisting>
  <para>
   The loader is not accessed when including a file through the <literal>phar</literal>
   stream wrapper like so:
  </para>
  <programlisting role="php">
   <![CDATA[
<?php
include 'phar://myphar.phar/somefile.php';
?>
   ]]>
  </programlisting>

 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>stub</parameter></term>
     <listitem>
      <para>
       A string or an open stream handle to use as the executable stub for this
       phar archive.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>length</parameter></term>
     <listitem>
      <para>
       
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   &return.success;
  </para>
 </refsect1>

 <refsect1 role="errors">
  &reftitle.errors;
  <para>
   <classname>UnexpectedValueException</classname> is thrown if
   <link linkend="ini.phar.readonly">phar.readonly</link> is enabled
   in php.ini.
   <classname>PharException</classname> is thrown if any problems are encountered
   flushing changes to disk.
  </para>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <informaltable>
   <tgroup cols="2">
    <thead>
     <row>
      <entry>&Version;</entry>
      <entry>&Description;</entry>
     </row>
    </thead>
    <tbody>
     <row>
      <entry>8.3.0</entry>
      <entry>
       Calling <methodname>Phar::setStub</methodname> with a
       <type>resource</type> and a <parameter>length</parameter>
       is now deprecated. Such calls should be replaced by:
       <code>$phar->setStub(stream_get_contents($resource));</code>
      </entry>
     </row>
    </tbody>
   </tgroup>
  </informaltable>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title>A <function>Phar::setStub</function> example</title>
    <para>
    </para>
    <programlisting role="php">
<![CDATA[
<?php
try {
    $p = new Phar(dirname(__FILE__) . '/brandnewphar.phar', 0, 'brandnewphar.phar');
    $p['a.php'] = '<?php var_dump("Hello");';
    $p->setStub('<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>');
    include 'phar://brandnewphar.phar/a.php';
    var_dump($p->getStub());
    $p['b.php'] = '<?php var_dump("World");';
    $p->setStub('<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>');
    include 'phar://brandnewphar.phar/b.php';
    var_dump($p->getStub());
} catch (Exception $e) {
    echo 'Write operations failed on brandnewphar.phar: ', $e;
}
?>
]]>
    </programlisting>
    &example.outputs;
    <screen>
<![CDATA[
string(5) "Hello"
string(82) "<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>"
string(5) "World"
string(83) "<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>"
]]>
    </screen>
   </example>
  </para>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>Phar::getStub</function></member>
    <member><function>Phar::createDefaultStub</function></member>
   </simplelist>
  </para>
 </refsect1>

</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
