Edit Files and Streams

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 these functions. You should use an alternative approach in JPHP - php\io\Stream class and its chlidren.


use php\io\Stream;
use php\io\FileStream;

$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 {

// instead of ...

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

You still can use util class methods of Stream:

$str = Stream::getContents('path/to/file');

// instead of
$str = file_get_contents('path/to/tile');

The Stream class is an abstract class which has a few util methods and child classes:

How to include a stream?

Yes, it’s supported by default, you can do like in the next example:

include "res://MyClass.php";
include "file://...."; 

// you cannot use external resources as http, ftp
// it will not work
include "http://...";

Files and Directories

To work with files and directories in JPHP you can use the php\io\File class:

use php\io\File;

$file = new File('path/to/file');

$file->isFile(); // instead of is_file
$file->isDirectory(); // instead of is_dir