<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >stream_wrapper_register</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="Stream Functions" HREF="ref.stream.html"><LINK REL="PREVIOUS" TITLE="stream_socket_shutdown" HREF="function.stream-socket-shutdown.html"><LINK REL="NEXT" TITLE="stream_wrapper_restore" HREF="function.stream-wrapper-restore.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.stream-socket-shutdown.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.stream-wrapper-restore.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.stream-wrapper-register" ></A >stream_wrapper_register</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN218064" ></A ><P > (PHP 4 >= 4.3.2, PHP 5)</P >stream_wrapper_register -- Register a URL wrapper implemented as a PHP class</DIV ><DIV CLASS="refsect1" ><A NAME="AEN218067" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >stream_wrapper_register</B > ( string protocol, string classname )<BR ></BR ><P > <B CLASS="function" >stream_wrapper_register()</B > allows you to implement your own protocol handlers and streams for use with all the other filesystem functions (such as <A HREF="function.fopen.html" ><B CLASS="function" >fopen()</B ></A >, <A HREF="function.fread.html" ><B CLASS="function" >fread()</B ></A > etc.). </P ><P > To implement a wrapper, you need to define a class with a number of member functions, as defined below. When someone fopens your stream, PHP will create an instance of <CODE CLASS="parameter" >classname</CODE > and then call methods on that instance. You must implement the methods exactly as described below - doing otherwise will lead to undefined behaviour. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B > As of PHP 5.0.0 the instance of <CODE CLASS="parameter" >classname</CODE > will be populated with a <CODE CLASS="parameter" >context</CODE > property referencing a <TT CLASS="literal" >Context Resource</TT > which may be accessed with <A HREF="function.stream-context-get-options.html" ><B CLASS="function" >stream_context_get_options()</B ></A >. If no context was passed to the stream creation function, <CODE CLASS="parameter" >context</CODE > will be set to <TT CLASS="constant" ><B >NULL</B ></TT >. </P ></BLOCKQUOTE ></DIV ><P > <B CLASS="function" >stream_wrapper_register()</B > will return <TT CLASS="constant" ><B >FALSE</B ></TT > if the <CODE CLASS="parameter" >protocol</CODE > already has a handler. </P >bool <B CLASS="methodname" >stream_open</B > ( string path, string mode, int options, string opened_path )<BR ></BR ><P > This method is called immediately after your stream object is created. <CODE CLASS="parameter" >path</CODE > specifies the URL that was passed to <A HREF="function.fopen.html" ><B CLASS="function" >fopen()</B ></A > and that this object is expected to retrieve. You can use <A HREF="function.parse-url.html" ><B CLASS="function" >parse_url()</B ></A > to break it apart. </P ><P > <CODE CLASS="parameter" >mode</CODE > is the mode used to open the file, as detailed for <A HREF="function.fopen.html" ><B CLASS="function" >fopen()</B ></A >. You are responsible for checking that <CODE CLASS="parameter" >mode</CODE > is valid for the <CODE CLASS="parameter" >path</CODE > requested. </P ><P > <CODE CLASS="parameter" >options</CODE > holds additional flags set by the streams API. It can hold one or more of the following values OR'd together. <DIV CLASS="informaltable" ><P ></P ><A NAME="AEN218122" ></A ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><THEAD ><TR ><TH >Flag</TH ><TH >Description</TH ></TR ></THEAD ><TBODY ><TR ><TD >STREAM_USE_PATH</TD ><TD >If <CODE CLASS="parameter" >path</CODE > is relative, search for the resource using the include_path. </TD ></TR ><TR ><TD >STREAM_REPORT_ERRORS</TD ><TD >If this flag is set, you are responsible for raising errors using <A HREF="function.trigger-error.html" ><B CLASS="function" >trigger_error()</B ></A > during opening of the stream. If this flag is not set, you should not raise any errors. </TD ></TR ></TBODY ></TABLE ><P ></P ></DIV > </P ><P > If the <CODE CLASS="parameter" >path</CODE > is opened successfully, and STREAM_USE_PATH is set in <CODE CLASS="parameter" >options</CODE >, you should set <CODE CLASS="parameter" >opened_path</CODE > to the full path of the file/resource that was actually opened. </P ><P > If the requested resource was opened successfully, you should return <TT CLASS="constant" ><B >TRUE</B ></TT >, otherwise you should return <TT CLASS="constant" ><B >FALSE</B ></TT > </P >void <B CLASS="methodname" >stream_close</B > ( void )<BR ></BR ><P > This method is called when the stream is closed, using <A HREF="function.fclose.html" ><B CLASS="function" >fclose()</B ></A >. You must release any resources that were locked or allocated by the stream. </P >string <B CLASS="methodname" >stream_read</B > ( int count )<BR ></BR ><P > This method is called in response to <A HREF="function.fread.html" ><B CLASS="function" >fread()</B ></A > and <A HREF="function.fgets.html" ><B CLASS="function" >fgets()</B ></A > calls on the stream. You must return up-to <CODE CLASS="parameter" >count</CODE > bytes of data from the current read/write position as a string. If there are less than <CODE CLASS="parameter" >count</CODE > bytes available, return as many as are available. If no more data is available, return either <TT CLASS="constant" ><B >FALSE</B ></TT > or an empty string. You must also update the read/write position of the stream by the number of bytes that were successfully read. </P >int <B CLASS="methodname" >stream_write</B > ( string data )<BR ></BR ><P > This method is called in response to <A HREF="function.fwrite.html" ><B CLASS="function" >fwrite()</B ></A > calls on the stream. You should store <CODE CLASS="parameter" >data</CODE > into the underlying storage used by your stream. If there is not enough room, try to store as many bytes as possible. You should return the number of bytes that were successfully stored in the stream, or 0 if none could be stored. You must also update the read/write position of the stream by the number of bytes that were successfully written. </P >bool <B CLASS="methodname" >stream_eof</B > ( void )<BR ></BR ><P > This method is called in response to <A HREF="function.feof.html" ><B CLASS="function" >feof()</B ></A > calls on the stream. You should return <TT CLASS="constant" ><B >TRUE</B ></TT > if the read/write position is at the end of the stream and if no more data is available to be read, or <TT CLASS="constant" ><B >FALSE</B ></TT > otherwise. </P >int <B CLASS="methodname" >stream_tell</B > ( void )<BR ></BR ><P > This method is called in response to <A HREF="function.ftell.html" ><B CLASS="function" >ftell()</B ></A > calls on the stream. You should return the current read/write position of the stream. </P >bool <B CLASS="methodname" >stream_seek</B > ( int offset, int whence )<BR ></BR ><P > This method is called in response to <A HREF="function.fseek.html" ><B CLASS="function" >fseek()</B ></A > calls on the stream. You should update the read/write position of the stream according to <CODE CLASS="parameter" >offset</CODE > and <CODE CLASS="parameter" >whence</CODE >. See <A HREF="function.fseek.html" ><B CLASS="function" >fseek()</B ></A > for more information about these parameters. Return <TT CLASS="constant" ><B >TRUE</B ></TT > if the position was updated, <TT CLASS="constant" ><B >FALSE</B ></TT > otherwise. </P >bool <B CLASS="methodname" >stream_flush</B > ( void )<BR ></BR ><P > This method is called in response to <A HREF="function.fflush.html" ><B CLASS="function" >fflush()</B ></A > calls on the stream. If you have cached data in your stream but not yet stored it into the underlying storage, you should do so now. Return <TT CLASS="constant" ><B >TRUE</B ></TT > if the cached data was successfully stored (or if there was no data to store), or <TT CLASS="constant" ><B >FALSE</B ></TT > if the data could not be stored. </P >array <B CLASS="methodname" >stream_stat</B > ( void )<BR ></BR ><P > This method is called in response to <A HREF="function.fstat.html" ><B CLASS="function" >fstat()</B ></A > calls on the stream and should return an array containing the same values as appropriate for the stream. </P >bool <B CLASS="methodname" >unlink</B > ( string path )<BR ></BR ><P > This method is called in response to <A HREF="function.unlink.html" ><B CLASS="function" >unlink()</B ></A > calls on URL paths associated with the wrapper and should attempt to delete the item specified by <CODE CLASS="parameter" >path</CODE >. It should return <TT CLASS="constant" ><B >TRUE</B ></TT > on success or <TT CLASS="constant" ><B >FALSE</B ></TT > on failure. In order for the appropriate error message to be returned, do not define this method if your wrapper does not support unlinking. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B > Userspace wrapper unlink method is not supported prior to PHP 5.0.0. </P ></BLOCKQUOTE ></DIV >bool <B CLASS="methodname" >rename</B > ( string path_from, string path_to )<BR ></BR ><P > This method is called in response to <A HREF="function.rename.html" ><B CLASS="function" >rename()</B ></A > calls on URL paths associated with the wrapper and should attempt to rename the item specified by <CODE CLASS="parameter" >path_from</CODE > to the specification given by <CODE CLASS="parameter" >path_to</CODE >. It should return <TT CLASS="constant" ><B >TRUE</B ></TT > on success or <TT CLASS="constant" ><B >FALSE</B ></TT > on failure. In order for the appropriate error message to be returned, do not define this method if your wrapper does not support renaming. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B > Userspace wrapper rename method is not supported prior to PHP 5.0.0. </P ></BLOCKQUOTE ></DIV >bool <B CLASS="methodname" >mkdir</B > ( string path, int mode, int options )<BR ></BR ><P > This method is called in response to <A HREF="function.mkdir.html" ><B CLASS="function" >mkdir()</B ></A > calls on URL paths associated with the wrapper and should attempt to create the directory specified by <CODE CLASS="parameter" >path</CODE >. It should return <TT CLASS="constant" ><B >TRUE</B ></TT > on success or <TT CLASS="constant" ><B >FALSE</B ></TT > on failure. In order for the appropriate error message to be returned, do not define this method if your wrapper does not support creating directories. Posible values for <CODE CLASS="parameter" >options</CODE > include <TT CLASS="constant" ><B >STREAM_REPORT_ERRORS</B ></TT > and <TT CLASS="constant" ><B >STREAM_MKDIR_RECURSIVE</B ></TT >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B > Userspace wrapper mkdir method is not supported prior to PHP 5.0.0. </P ></BLOCKQUOTE ></DIV >bool <B CLASS="methodname" >rmdir</B > ( string path, int options )<BR ></BR ><P > This method is called in response to <A HREF="function.rmdir.html" ><B CLASS="function" >rmdir()</B ></A > calls on URL paths associated with the wrapper and should attempt to remove the directory specified by <CODE CLASS="parameter" >path</CODE >. It should return <TT CLASS="constant" ><B >TRUE</B ></TT > on success or <TT CLASS="constant" ><B >FALSE</B ></TT > on failure. In order for the appropriate error message to be returned, do not define this method if your wrapper does not support removing directories. Possible values for <CODE CLASS="parameter" >options</CODE > include <TT CLASS="constant" ><B >STREAM_REPORT_ERRORS</B ></TT >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B > Userspace wrapper rmdir method is not supported prior to PHP 5.0.0. </P ></BLOCKQUOTE ></DIV >bool <B CLASS="methodname" >dir_opendir</B > ( string path, int options )<BR ></BR ><P > This method is called immediately when your stream object is created for examining directory contents with <A HREF="function.opendir.html" ><B CLASS="function" >opendir()</B ></A >. <CODE CLASS="parameter" >path</CODE > specifies the URL that was passed to <A HREF="function.opendir.html" ><B CLASS="function" >opendir()</B ></A > and that this object is expected to explore. You can use <A HREF="function.parse-url.html" ><B CLASS="function" >parse_url()</B ></A > to break it apart. </P >array <B CLASS="methodname" >url_stat</B > ( string path, int flags )<BR ></BR ><P > This method is called in response to <A HREF="function.stat.html" ><B CLASS="function" >stat()</B ></A > calls on the URL paths associated with the wrapper and should return as many elements in common with the system function as possible. Unknown or unavailable values should be set to a rational value (usually <TT CLASS="constant" ><B >0</B ></TT >). </P ><P > <CODE CLASS="parameter" >flags</CODE > holds additional flags set by the streams API. It can hold one or more of the following values OR'd together. <DIV CLASS="informaltable" ><P ></P ><A NAME="AEN218313" ></A ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><THEAD ><TR ><TH >Flag</TH ><TH >Description</TH ></TR ></THEAD ><TBODY ><TR ><TD >STREAM_URL_STAT_LINK</TD ><TD > For resources with the ability to link to other resource (such as an HTTP Location: forward, or a filesystem symlink). This flag specified that only information about the link itself should be returned, not the resource pointed to by the link. This flag is set in response to calls to <A HREF="function.lstat.html" ><B CLASS="function" >lstat()</B ></A >, <A HREF="function.is-link.html" ><B CLASS="function" >is_link()</B ></A >, or <A HREF="function.filetype.html" ><B CLASS="function" >filetype()</B ></A >. </TD ></TR ><TR ><TD >STREAM_URL_STAT_QUIET</TD ><TD >If this flag is set, your wrapper should not raise any errors. If this flag is not set, you are responsible for reporting errors using the <A HREF="function.trigger-error.html" ><B CLASS="function" >trigger_error()</B ></A > function during stating of the path. </TD ></TR ></TBODY ></TABLE ><P ></P ></DIV > </P >string <B CLASS="methodname" >dir_readdir</B > ( void )<BR ></BR ><P > This method is called in response to <A HREF="function.readdir.html" ><B CLASS="function" >readdir()</B ></A > and should return a string representing the next filename in the location opened by <B CLASS="function" >dir_opendir()</B >. </P >bool <B CLASS="methodname" >dir_rewinddir</B > ( void )<BR ></BR ><P > This method is called in response to <A HREF="function.rewinddir.html" ><B CLASS="function" >rewinddir()</B ></A > and should reset the output generated by <B CLASS="function" >dir_readdir()</B >. i.e.: The next call to <B CLASS="function" >dir_readdir()</B > should return the first entry in the location returned by <B CLASS="function" >dir_opendir()</B >. </P >bool <B CLASS="methodname" >dir_closedir</B > ( void )<BR ></BR ><P > This method is called in response to <A HREF="function.closedir.html" ><B CLASS="function" >closedir()</B ></A >. You should release any resources which were locked or allocated during the opening and use of the directory stream. </P ><P > The example below implements a var:// protocol handler that allows read/write access to a named global variable using standard filesystem stream functions such as <A HREF="function.fread.html" ><B CLASS="function" >fread()</B ></A >. The var:// protocol implemented below, given the URL "var://foo" will read/write data to/from $GLOBALS["foo"]. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN218354" ></A ><P ><B >Exemplo 1. A Stream for reading/writing global variables</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /><br /></font><font color="#007700">class </font><font color="#0000BB">VariableStream </font><font color="#007700">{<br /> var </font><font color="#0000BB">$position</font><font color="#007700">;<br /> var </font><font color="#0000BB">$varname</font><font color="#007700">;<br /> <br /> function </font><font color="#0000BB">stream_open</font><font color="#007700">(</font><font color="#0000BB">$path</font><font color="#007700">, </font><font color="#0000BB">$mode</font><font color="#007700">, </font><font color="#0000BB">$options</font><font color="#007700">, &</font><font color="#0000BB">$opened_path</font><font color="#007700">) <br /> {<br /> </font><font color="#0000BB">$url </font><font color="#007700">= </font><font color="#0000BB">parse_url</font><font color="#007700">(</font><font color="#0000BB">$path</font><font color="#007700">);<br /> </font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">varname </font><font color="#007700">= </font><font color="#0000BB">$url</font><font color="#007700">[</font><font color="#DD0000">"host"</font><font color="#007700">];<br /> </font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">position </font><font color="#007700">= </font><font color="#0000BB">0</font><font color="#007700">;<br /> <br /> return </font><font color="#0000BB">true</font><font color="#007700">;<br /> }<br /><br /> function </font><font color="#0000BB">stream_read</font><font color="#007700">(</font><font color="#0000BB">$count</font><font color="#007700">) <br /> {<br /> </font><font color="#0000BB">$ret </font><font color="#007700">= </font><font color="#0000BB">substr</font><font color="#007700">(</font><font color="#0000BB">$GLOBALS</font><font color="#007700">[</font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">varname</font><font color="#007700">], </font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">position</font><font color="#007700">, </font><font color="#0000BB">$count</font><font color="#007700">);<br /> </font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">position </font><font color="#007700">+= </font><font color="#0000BB">strlen</font><font color="#007700">(</font><font color="#0000BB">$ret</font><font color="#007700">);<br /> return </font><font color="#0000BB">$ret</font><font color="#007700">;<br /> }<br /><br /> function </font><font color="#0000BB">stream_write</font><font color="#007700">(</font><font color="#0000BB">$data</font><font color="#007700">) <br /> {<br /> </font><font color="#0000BB">$left </font><font color="#007700">= </font><font color="#0000BB">substr</font><font color="#007700">(</font><font color="#0000BB">$GLOBALS</font><font color="#007700">[</font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">varname</font><font color="#007700">], </font><font color="#0000BB">0</font><font color="#007700">, </font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">position</font><font color="#007700">);<br /> </font><font color="#0000BB">$right </font><font color="#007700">= </font><font color="#0000BB">substr</font><font color="#007700">(</font><font color="#0000BB">$GLOBALS</font><font color="#007700">[</font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">varname</font><font color="#007700">], </font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">position </font><font color="#007700">+ </font><font color="#0000BB">strlen</font><font color="#007700">(</font><font color="#0000BB">$data</font><font color="#007700">));<br /> </font><font color="#0000BB">$GLOBALS</font><font color="#007700">[</font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">varname</font><font color="#007700">] = </font><font color="#0000BB">$left </font><font color="#007700">. </font><font color="#0000BB">$data </font><font color="#007700">. </font><font color="#0000BB">$right</font><font color="#007700">;<br /> </font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">position </font><font color="#007700">+= </font><font color="#0000BB">strlen</font><font color="#007700">(</font><font color="#0000BB">$data</font><font color="#007700">);<br /> return </font><font color="#0000BB">strlen</font><font color="#007700">(</font><font color="#0000BB">$data</font><font color="#007700">);<br /> }<br /><br /> function </font><font color="#0000BB">stream_tell</font><font color="#007700">() <br /> {<br /> return </font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">position</font><font color="#007700">;<br /> }<br /><br /> function </font><font color="#0000BB">stream_eof</font><font color="#007700">() <br /> {<br /> return </font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">position </font><font color="#007700">>= </font><font color="#0000BB">strlen</font><font color="#007700">(</font><font color="#0000BB">$GLOBALS</font><font color="#007700">[</font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">varname</font><font color="#007700">]);<br /> }<br /><br /> function </font><font color="#0000BB">stream_seek</font><font color="#007700">(</font><font color="#0000BB">$offset</font><font color="#007700">, </font><font color="#0000BB">$whence</font><font color="#007700">) <br /> {<br /> switch (</font><font color="#0000BB">$whence</font><font color="#007700">) {<br /> case </font><font color="#0000BB">SEEK_SET</font><font color="#007700">:<br /> if (</font><font color="#0000BB">$offset </font><font color="#007700">< </font><font color="#0000BB">strlen</font><font color="#007700">(</font><font color="#0000BB">$GLOBALS</font><font color="#007700">[</font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">varname</font><font color="#007700">]) && </font><font color="#0000BB">$offset </font><font color="#007700">>= </font><font color="#0000BB">0</font><font color="#007700">) {<br /> </font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">position </font><font color="#007700">= </font><font color="#0000BB">$offset</font><font color="#007700">;<br /> return </font><font color="#0000BB">true</font><font color="#007700">;<br /> } else {<br /> return </font><font color="#0000BB">false</font><font color="#007700">;<br /> }<br /> break;<br /> <br /> case </font><font color="#0000BB">SEEK_CUR</font><font color="#007700">:<br /> if (</font><font color="#0000BB">$offset </font><font color="#007700">>= </font><font color="#0000BB">0</font><font color="#007700">) {<br /> </font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">position </font><font color="#007700">+= </font><font color="#0000BB">$offset</font><font color="#007700">;<br /> return </font><font color="#0000BB">true</font><font color="#007700">;<br /> } else {<br /> return </font><font color="#0000BB">false</font><font color="#007700">;<br /> }<br /> break;<br /> <br /> case </font><font color="#0000BB">SEEK_END</font><font color="#007700">:<br /> if (</font><font color="#0000BB">strlen</font><font color="#007700">(</font><font color="#0000BB">$GLOBALS</font><font color="#007700">[</font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">varname</font><font color="#007700">]) + </font><font color="#0000BB">$offset </font><font color="#007700">>= </font><font color="#0000BB">0</font><font color="#007700">) {<br /> </font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">position </font><font color="#007700">= </font><font color="#0000BB">strlen</font><font color="#007700">(</font><font color="#0000BB">$GLOBALS</font><font color="#007700">[</font><font color="#0000BB">$this</font><font color="#007700">-></font><font color="#0000BB">varname</font><font color="#007700">]) + </font><font color="#0000BB">$offset</font><font color="#007700">;<br /> return </font><font color="#0000BB">true</font><font color="#007700">;<br /> } else {<br /> return </font><font color="#0000BB">false</font><font color="#007700">;<br /> }<br /> break;<br /> <br /> default:<br /> return </font><font color="#0000BB">false</font><font color="#007700">;<br /> }<br /> }<br />}<br /><br /></font><font color="#0000BB">stream_wrapper_register</font><font color="#007700">(</font><font color="#DD0000">"var"</font><font color="#007700">, </font><font color="#DD0000">"VariableStream"</font><font color="#007700">)<br /> or die(</font><font color="#DD0000">"Failed to register protocol"</font><font color="#007700">);<br /><br /></font><font color="#0000BB">$myvar </font><font color="#007700">= </font><font color="#DD0000">""</font><font color="#007700">;<br /> <br /></font><font color="#0000BB">$fp </font><font color="#007700">= </font><font color="#0000BB">fopen</font><font color="#007700">(</font><font color="#DD0000">"var://myvar"</font><font color="#007700">, </font><font color="#DD0000">"r+"</font><font color="#007700">);<br /><br /></font><font color="#0000BB">fwrite</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">, </font><font color="#DD0000">"line1\n"</font><font color="#007700">);<br /></font><font color="#0000BB">fwrite</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">, </font><font color="#DD0000">"line2\n"</font><font color="#007700">);<br /></font><font color="#0000BB">fwrite</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">, </font><font color="#DD0000">"line3\n"</font><font color="#007700">);<br /><br /></font><font color="#0000BB">rewind</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">);<br />while (!</font><font color="#0000BB">feof</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">)) {<br /> echo </font><font color="#0000BB">fgets</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">);<br />}<br /></font><font color="#0000BB">fclose</font><font color="#007700">(</font><font color="#0000BB">$fp</font><font color="#007700">);<br /></font><font color="#0000BB">var_dump</font><font color="#007700">(</font><font color="#0000BB">$myvar</font><font color="#007700">);<br /><br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.stream-socket-shutdown.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.stream-wrapper-restore.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >stream_socket_shutdown</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.stream.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >stream_wrapper_restore</TD ></TR ></TABLE ></DIV ></BODY ></HTML >