Skip to content

Files and Streams

Dmitriy Zayceff edited this page Apr 29, 2015 · 11 revisions

Zend PHP has a few functions for working with files (or streams), these are named like in the C language: fopen, fclose, fwrite, etc. JPHP does not implement this functions. You should use an alternative approach in JPHP - php\io\Stream class and its chlidren.

use php\io\Stream;

$stream = Stream::of('path/to/file', 'r');
// or
$stream = new FileStream('path/to/file', 'r');

try {
   $str = $stream->read(10);
   // or read fully
   $str = $stream->readFully();
} finally {
   $stream->close();
}

// instead of ...

$fp = fopen('path/to/file', 'r');
$str = fread($fp, 10);
fclose($fp);

Clone this wiki locally