This is an old revision of the document!

Request for comments: Streamline Phar API

  • Version: 0.1
  • Date: 2008-03-28
  • Author: Lars Strojny
  • Status: Under development


This proposal aims to streamline the Phar API to make it more usable and intuitive.

Concrete change proposals


Modifying Phar archive content

  • offsetSet()
  • offsetGet()
  • offsetExists()
  • offsetUnset()

In the current API, every path is represented by a single array index. This is counter intuitive, as a multi-dimensional structure (the archive) is represented as a single dimensional array accessible object. The idea is to change that object to represent every path element (e.g. “bar” in “foo/bar/baz”) as a single index. This would be accomplished by letting the DirectoryIterator implement ArrayAccess.

$phar = new Phar('test.phar');
$phar['path']['to']['file'] = 'test'; // Set content 'test' in path/to/file

Adding isWritable() method


Add an isWritable() method to determine whether an archive can be written or not. Not being able to write an archive either means it is disabled in the php.ini (see Phar::canWrite()) or that PHP can't write to the requested location of the phar archive.

$phar = new Phar('test.phar');
if ($phar->isWritable()) {
    $phar['path']['to']['file'] = "test";

Adding createDirectory()


Add the method Phar→createDirectory() to explicitly create a new directory. createDirectory() will return another Phar object and takes a dirname (string) as an argument.

$phar = new Phar('test.phar');
$dir = $phar->createDirectory('foo');
$dir['file'] = 'content'; // Set the file 'foo/file' to 'content'


PharFileInfo is derived from SplFileInfo. Every change in SplFileInfo will be visible in PharFileInfo.



Add two simple methods to write/retrieve content.

$file = new SplFileInfo("file");
echo $file->getContent(); // returns 'foo'

get*Time() methods

  • getMTime()
  • getATime()
  • getCTime()

Rename the methods to make them more independent from their origin, the UNIX naming scheme and therefore better to understand for a people with non-UNIX backgrounds. Leave the original method names but trigger deprecation warnings and remove them in PHP 6.

  • getMTime() ⇒ getModificationTime()
  • getATime() ⇒ getAccessTime()
  • getCTime() ⇒ getCreateTime()


setCompressed*() methods

  • setCompressedBZIP2()
  • setCompressedGZ()
  • setUncompressed()

Unify this methods to a single method compress(). The compress method will take one argument indicating the compression algorithm. The compression algorithm is represented as a Phar class constant. The setUncompressed() method should be renamed to uncompress().

$file->compress(Phar::BZ2); // Compress with bzip2
$file->compress(Phar::GZ);  // Compress with gzip

isCompressed*() methods

  • isCompressedBZIP2()
  • isCompressedGZ()
  • isCompressed()

Unify this methods to one PharFileInfo::isCompressed(). The new isCompressed() would take an optional argument with the compression algorithm. The compression algorithm is represented as a Phar class constant.

$file->isCompressed(); // Is the file compressed at all?
$file->isCompressed(Phar::GZ); // Is the file gzip compressed?
$file->isCompressed(Phar::BZ2); // Is the file bzip compressed?
rfc/streamline-phar-api.1206716965.txt.gz · Last modified: 2017/09/22 13:28 (external edit)