<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Create a phar-file format specific stub</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="phar.count.html">Phar::count</a></div> <div class="next" style="text-align: right; float: right;"><a href="phar.decompress.html">Phar::decompress</a></div> <div class="up"><a href="class.phar.html">Phar</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="phar.createdefaultstub" class="refentry"> <div class="refnamediv"> <h1 class="refname">Phar::createDefaultStub</h1> <p class="verinfo">(Unknown)</p><p class="refpurpose"><span class="refname">Phar::createDefaultStub</span> — <span class="dc-title">Create a phar-file format specific stub</span></p> </div> <div class="refsect1 description" id="refsect1-phar.createdefaultstub-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">final</span> <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">string</span> <span class="methodname"><strong>Phar::createDefaultStub</strong></span> ([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$indexfile</code></span> [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$webindexfile</code></span> ]] )</div> <p class="para rdfs-comment"> This method is intended for creation of phar-file format-specific stubs, and is not intended for use with tar- or zip-based phar archives. </p> <p class="para"> Phar archives contain a bootstrap loader, or <em>stub</em> written in PHP that is executed when the archive is executed in PHP either via include: <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #007700">include </span><span style="color: #DD0000">'myphar.phar'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> or by simple execution: <div class="example-contents screen"> <div class="cdata"><pre> php myphar.phar </pre></div> </div> </p> <p class="para"> This method provides a simple and easy method to create a stub that will run a startup file from the phar archive. In addition, different files can be specified for running the phar archive from the command line versus through a web server. The loader stub also calls <span class="function"><a href="phar.interceptfilefuncs.html" class="function">Phar::interceptFileFuncs()</a></span> to allow easy bundling of a PHP application that accesses the file system. If the phar extension is not present, the loader stub will extract the phar archive to a temporary directory and then operate on the files. A shutdown function erases the temporary files on exit. </p> </div> <div class="refsect1 returnvalues" id="refsect1-phar.createdefaultstub-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns a string containing the contents of a customized bootstrap loader (stub) that allows the created Phar archive to work with or without the Phar extension enabled. </p> </div> <div class="refsect1 errors" id="refsect1-phar.createdefaultstub-errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> Throws <a href="class.unexpectedvalueexception.html" class="classname">UnexpectedValueException</a> if either parameter is longer than 400 bytes. </p> </div> <div class="refsect1 examples" id="refsect1-phar.createdefaultstub-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-674"> <p><strong>Example #1 A <span class="function"><strong>Phar::createDefaultStub()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #007700">try {<br /> </span><span style="color: #0000BB">$phar </span><span style="color: #007700">= new </span><span style="color: #0000BB">Phar</span><span style="color: #007700">(</span><span style="color: #DD0000">'myphar.phar'</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$phar</span><span style="color: #007700">-></span><span style="color: #0000BB">setStub</span><span style="color: #007700">(</span><span style="color: #0000BB">$phar</span><span style="color: #007700">-></span><span style="color: #0000BB">createDefaultStub</span><span style="color: #007700">(</span><span style="color: #DD0000">'cli.php'</span><span style="color: #007700">, </span><span style="color: #DD0000">'web/index.php'</span><span style="color: #007700">));<br />} catch (</span><span style="color: #0000BB">Exception $e</span><span style="color: #007700">) {<br /> </span><span style="color: #FF8000">// handle errors<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-phar.createdefaultstub-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="phar.setstub.html" class="function" rel="rdfs-seeAlso">Phar::setStub()</a> - Used to set the PHP loader or bootstrap stub of a Phar archive</span></li> <li class="member"> <span class="function"><a href="phar.getstub.html" class="function" rel="rdfs-seeAlso">Phar::getStub()</a> - Return the PHP loader or bootstrap stub of a Phar archive</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="phar.count.html">Phar::count</a></div> <div class="next" style="text-align: right; float: right;"><a href="phar.decompress.html">Phar::decompress</a></div> <div class="up"><a href="class.phar.html">Phar</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>