<!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>Construct a new temporary file object</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="class.spltempfileobject.html">SplTempFileObject</a></div> <div class="next" style="text-align: right; float: right;"><a href="spl.misc.html">Miscellaneous Classes and Interfaces</a></div> <div class="up"><a href="class.spltempfileobject.html">SplTempFileObject</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="spltempfileobject.construct" class="refentry"> <div class="refnamediv"> <h1 class="refname">SplTempFileObject::__construct</h1> <p class="verinfo">(PHP 5 >= 5.1.2)</p><p class="refpurpose"><span class="refname">SplTempFileObject::__construct</span> — <span class="dc-title">Construct a new temporary file object</span></p> </div> <div class="refsect1 description" id="refsect1-spltempfileobject.construct-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="methodname"><strong>SplTempFileObject::__construct</strong></span> ([ <span class="methodparam"><span class="type">int</span> <code class="parameter">$max_memory</code></span> ] )</div> <p class="para rdfs-comment"> Construct a new temporary file object. </p> </div> <div class="refsect1 parameters" id="refsect1-spltempfileobject.construct-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">max_memory</code></em></span> <dd> <p class="para"> The maximum amount of memory (in bytes, default is 2 MB) for the temporary file to use. If the temporary file exceeds this size, it will be moved to a file in the system's temp directory. </p> <p class="para"> If <em><code class="parameter">max_memory</code></em> is negative, only memory will be used. If <em><code class="parameter">max_memory</code></em> is zero, no memory will be used. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-spltempfileobject.construct-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> No value is returned. </p> </div> <div class="refsect1 errors" id="refsect1-spltempfileobject.construct-errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> Throws a <a href="class.runtimeexception.html" class="classname">RuntimeException</a> if an error occurs. </p> </div> <div class="refsect1 examples" id="refsect1-spltempfileobject.construct-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-3976"> <p><strong>Example #1 <span class="methodname"><strong>SplTempFileObject()</strong></span> example</strong></p> <div class="example-contents"><p>This example writes a temporary file in memory which can be written to and read from.</p></div> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$temp </span><span style="color: #007700">= new </span><span style="color: #0000BB">SplTempFileObject</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$temp</span><span style="color: #007700">-></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #DD0000">"This is the first line\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$temp</span><span style="color: #007700">-></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #DD0000">"And this is the second.\n"</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Written " </span><span style="color: #007700">. </span><span style="color: #0000BB">$temp</span><span style="color: #007700">-></span><span style="color: #0000BB">ftell</span><span style="color: #007700">() . </span><span style="color: #DD0000">" bytes to temporary file.\n\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Rewind and read what was written<br /></span><span style="color: #0000BB">$temp</span><span style="color: #007700">-></span><span style="color: #0000BB">rewind</span><span style="color: #007700">();<br />foreach (</span><span style="color: #0000BB">$temp </span><span style="color: #007700">as </span><span style="color: #0000BB">$line</span><span style="color: #007700">) {<br /> echo </span><span style="color: #0000BB">$line</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> Written 47 bytes to temporary file. This is the first line And this is the second. </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-spltempfileobject.construct-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="class.splfileobject.html" class="classname">SplFileObject</a></li> <li class="member"> <a href="wrappers.php.html" class="link">PHP input/output streams</a> (for <em>php://temp</em> and <em>php://memory</em>) </li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="class.spltempfileobject.html">SplTempFileObject</a></div> <div class="next" style="text-align: right; float: right;"><a href="spl.misc.html">Miscellaneous Classes and Interfaces</a></div> <div class="up"><a href="class.spltempfileobject.html">SplTempFileObject</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>