[ class tree: Stream_Var ] [ index: Stream_Var ] [ all elements ]

Class: Stream_Var

Source Location: /Stream_Var-1.1.0/Stream/Var.php

Class Overview

Stream wrapper to access a variable



  • 0.2.1


Inherited Variables

Inherited Methods

Class Details

[line 83]
Stream wrapper to access a variable

Stream wrappers allow you to access any datasource using PHP's file manipulation functions like fopen(), fclose(), fseek(), ftell(),.. as well as directory functions like opendir() readdir() and closedir().

This wrapper allows you to access any variable using these functions. You have to specify a scope (GLOBALS, _GET, _POST, etc.) as the host and the variable name as the path. If you want to access a string, that is stored in an array, you can use this array like you would use a directory.


  1.   require_once '../Var.php';
  2.   stream_wrapper_register"var""Stream_Var" );
  4.   $fp fopen('var://GLOBALS/myArray/index','r');
  5.   $data fread($fp,100);
  6.   fclose($fp);

This wrapper also has support for dir functions, so it's possible to read any array, like you would read a directory. The following code will list all keys in an array. You could use fopen() to read the values for the keys.

  1.   require_once '../Var.php';
  2.   stream_wrapper_register"var""Stream_Var" );
  4.   $dh opendir('var://_SERVER');
  5.   while ($entry readdir($dh)) {
  6.       echo $entry."<br />";
  7.   }
  8.   closedir($dh);

This wrapper allows you to replace files and directories with structures in memory in any application, that relies on filesystem functions. But keep in mind that variables are not persistent during several request, unless you write to var://SESSION. But this can be used to replace temporary files with variables.

[ Top ]

Method Detail

dir_closedir   [line 457]

boolean dir_closedir( )

Close 'directory'
  • Access: public

[ Top ]

dir_opendir   [line 426]

boolean dir_opendir( string $path, array $options)

Open 'directory'
  • Access: public


string   $path   —  Path to the array (i.e. the directory)
array   $options   —  Not implemented, yet.

[ Top ]

dir_readdir   [line 487]

mixed dir_readdir( )

Read one entry from 'directory'
  • Return: Entry that has been read, or false if there are no entries left
  • Access: public

[ Top ]

dir_rewinddir   [line 470]

boolean dir_rewinddir( )

Rewind 'directory'
  • Access: public

[ Top ]

stream_close   [line 211]

void stream_close( )

Close the stream.
  • Access: public

[ Top ]

stream_eof   [line 187]

boolean stream_eof( )

Check for end of stream.
  • Return: True if at end of stream
  • Access: public

[ Top ]

stream_flush   [line 323]

boolean stream_flush( )

Write all data to storage.
  • Return: Always true
  • Access: public

[ Top ]

stream_open   [line 128]

boolean stream_open( string $path, string $mode, array $options, string &$opened_path)

Method used by fopen.
  • Access: public


string   $path   —  Path to the variable (e.g. var://GLOBALS/myArray/anyIndex)
string   $mode   —  Mode to open the stream, like 'r', 'w,',... ({@see fopen()})
array   $options   —  Options (not implemented yet)
string   &$opened_path   —  This will be set to the actual opened path

[ Top ]

stream_read   [line 226]

string stream_read( integer $count)

Read from the stream.
  • Return: Data that has been read
  • Access: public


integer   $count   —  Amount of bytes to read

[ Top ]

stream_seek   [line 281]

boolean stream_seek( integer $offset, integer $whence)

Move the position in the stream.
  • Return: True if the position could be reached
  • Access: public


integer   $offset   —  Offset
integer   $whence   —  Point from which the offset should be calculated

[ Top ]

stream_stat   [line 335]

array stream_stat( )

Return information about the stream.
  • Return: Information about the stream (currently only the length is included)
  • Access: public

[ Top ]

stream_tell   [line 199]

integer stream_tell( )

Return the current position.
  • Return: Current position in stream
  • Access: public

[ Top ]

stream_write   [line 250]

integer stream_write( mixed $data)

write to the stream.
  • Return: Number of bytes that were written
  • Access: public


mixed   $data   —  Data to write

[ Top ]

url_stat   [line 390]

array url_stat( string $path, integer $flags)

This method is called in response to stat() calls on the URL paths

As taken from the PHP Manual:

"This method is called in response to stat() 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 0)."

With regards to the implementation that is Stream_Var we can actually fake some of the data. For instance, the uid and gid can be that of the corrent posix_getuid and posix_getgid()

The following outlines the information that we essentially fake:

  • 'dev': is unknown and set to 0
  • 'ino': is unknown and set to 0
  • 'mode': set to 33216 (chmod 700 means user has read, write and execute on the file)
  • 'nlink': is unknown and set to 0
  • 'uid': if the method posix_getuid exist, this is called, otherwise 0 is returned
  • 'gid': if the method posix_getgid exist, this is called, otherwise 0 is returned
  • 'rdev' unknown and set to 0
  • 'size': is set to the strlen of the pointer.
  • 'atime': set to current value returned by time()
  • 'mtime': set to current value returned by time()
  • 'ctime': set to current value returned by time()
  • 'blksize': is unknown and set to 0
  • 'blocks': is unknown and set to 0


string   $path   —  The path to stat.
integer   $flags   —  Holds additional flags set by the streams API. It can hold one or more of the following values OR'd together.
  • STREAM_URL_STAT_LINK - currently this is ignored.
  • STREAM_URL_STAT_QUIET - makes call to strlen quiet

[ Top ]

Documentation generated on Mon, 11 Mar 2019 15:32:46 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.