# The Phar class

(PHP 5 >= 5.3.0, PHP 7, PECL phar >= 1.0.0)

## Introduction

The Phar class provides a high-level interface to accessing and creating phar archives.

## Class synopsis

Phar extends RecursiveDirectoryIterator implements Countable , ArrayAccess {
/* Inherited constants */
const int FilesystemIterator::CURRENT_AS_PATHNAME = 32 ;
const int FilesystemIterator::CURRENT_AS_FILEINFO = 0 ;
const int FilesystemIterator::CURRENT_AS_SELF = 16 ;
const int FilesystemIterator::CURRENT_MODE_MASK = 240 ;
const int FilesystemIterator::KEY_AS_PATHNAME = 0 ;
const int FilesystemIterator::KEY_AS_FILENAME = 256 ;
const int FilesystemIterator::FOLLOW_SYMLINKS = 512 ;
const int FilesystemIterator::KEY_MODE_MASK = 3840 ;
const int FilesystemIterator::NEW_CURRENT_AND_KEY = 256 ;
const int FilesystemIterator::SKIP_DOTS = 4096 ;
const int FilesystemIterator::UNIX_PATHS = 8192 ;
/* Methods */
public addEmptyDir ( string `$dirname` ) : void
public addFile ( string `$file` [, string `$localname` ] ) : void
public addFromString ( string `$localname` , string `$contents` ) : void
final public static apiVersion ( ) : string
public buildFromDirectory ( string `$base_dir` [, string `$regex` ] ) : array
public buildFromIterator ( Iterator `$iter` [, string `$base_directory` ] ) : array
final public static canCompress ([ int `$type` = 0 ] ) : bool
final public static canWrite ( ) : bool
public compress ( int `$compression` [, string `$extension` ] ) : Phar
public compressAllFilesBZIP2 ( ) : bool
public compressAllFilesGZ ( ) : bool
public compressFiles ( int `$compression` ) : void
public __construct ( string `$fname` [, int `$flags` [, string `$alias` ]] )
public convertToData ([ int `$format` = 9021976 [, int `$compression` = 9021976 [, string `$extension` ]]] ) : PharData
public convertToExecutable ([ int `$format` = 9021976 [, int `$compression` = 9021976 [, string `$extension` ]]] ) : Phar
public copy ( string `$oldfile` , string `$newfile` ) : bool
public count ( ) : int
final public static createDefaultStub ([ string `$indexfile` [, string `$webindexfile` ]] ) : string
public decompress ([ string `$extension` ] ) : Phar
public decompressFiles ( ) : bool
public delMetadata ( ) : bool
public delete ( string `$entry` ) : bool
public extractTo ( string `$pathto` [, string|array|null `$files` = `NULL` [, bool `$overwrite` = `FALSE` ]] ) : bool
public getAlias ( ) : string
public getMetadata ( ) : mixed
public getModified ( ) : bool
public getPath ( ) : string
public getSignature ( ) : array
public getStub ( ) : string
final public static getSupportedCompression ( ) : array
final public static getSupportedSignatures ( ) : array
public getVersion ( ) : string
public hasMetadata ( ) : bool
final public static interceptFileFuncs ( ) : void
public isBuffering ( ) : bool
public isCompressed ( ) : mixed
public isFileFormat ( int `$format` ) : bool
final public static isValidPharFilename ( string `$filename` [, bool `$executable` = `TRUE` ] ) : bool
public isWritable ( ) : bool
final public static loadPhar ( string `$filename` [, string `$alias` ] ) : bool
final public static mapPhar ([ string `$alias` [, int `$dataoffset` = 0 ]] ) : bool
final public static mount ( string `$pharpath` , string `$externalpath` ) : void
final public static mungServer ( array `$munglist` ) : void
public offsetExists ( string `$offset` ) : bool
public offsetGet ( string `$offset` ) : PharFileInfo
public offsetSet ( string `$offset` , string `$value` ) : void
public offsetUnset ( string `$offset` ) : bool
final public static running ([ bool `$retphar` = `TRUE` ] ) : string
public setAlias ( string `$alias` ) : bool
public setDefaultStub ([ string `$index` [, string `$webindex` ]] ) : bool
public setMetadata ( mixed `$metadata` ) : void
public setSignatureAlgorithm ( int `$sigtype` [, string `$privatekey` ] ) : void
public setStub ( string `$stub` [, int `$len` = -1 ] ) : bool
public startBuffering ( ) : void
public stopBuffering ( ) : void
public uncompressAllFiles ( ) : bool
final public static unlinkArchive ( string `$archive` ) : bool
final public static webPhar ([ string `$alias` [, string `$index` = "index.php" [, string `$f404` [, array `$mimetypes` [, callable `$rewrites` ]]]]] ) : void
}

## Table of Contents

- Phar::addEmptyDir — Add an empty directory to the phar archive
- Phar::addFile — Add a file from the filesystem to the phar archive
- Phar::addFromString — Add a file from a string to the phar archive
- Phar::apiVersion — Returns the api version
- Phar::buildFromDirectory — Construct a phar archive from the files within a directory
- Phar::buildFromIterator — Construct a phar archive from an iterator
- Phar::canCompress — Returns whether phar extension supports compression using either zlib or bzip2
- Phar::canWrite — Returns whether phar extension supports writing and creating phars
- Phar::compress — Compresses the entire Phar archive using Gzip or Bzip2 compression
- Phar::compressAllFilesBZIP2 — Compresses all files in the current Phar archive using Bzip2 compression
- Phar::compressAllFilesGZ — Compresses all files in the current Phar archive using Gzip compression
- Phar::compressFiles — Compresses all files in the current Phar archive
- Phar::__construct — Construct a Phar archive object
- Phar::convertToData — Convert a phar archive to a non-executable tar or zip file
- Phar::convertToExecutable — Convert a phar archive to another executable phar archive file format
- Phar::copy — Copy a file internal to the phar archive to another new file within the phar
- Phar::count — Returns the number of entries (files) in the Phar archive
- Phar::createDefaultStub — Create a phar-file format specific stub
- Phar::decompress — Decompresses the entire Phar archive
- Phar::decompressFiles — Decompresses all files in the current Phar archive
- Phar::delMetadata — Deletes the global metadata of the phar
- Phar::delete — Delete a file within a phar archive
- Phar::extractTo — Extract the contents of a phar archive to a directory
- Phar::getAlias — Get the alias for Phar
- Phar::getMetadata — Returns phar archive meta-data
- Phar::getModified — Return whether phar was modified
- Phar::getPath — Get the real path to the Phar archive on disk
- Phar::getSignature — Return MD5/SHA1/SHA256/SHA512/OpenSSL signature of a Phar archive
- Phar::getStub — Return the PHP loader or bootstrap stub of a Phar archive
- Phar::getSupportedCompression — Return array of supported compression algorithms
- Phar::getSupportedSignatures — Return array of supported signature types
- Phar::getVersion — Return version info of Phar archive
- Phar::hasMetadata — Returns whether phar has global meta-data
- Phar::interceptFileFuncs — Instructs phar to intercept fopen, file_get_contents, opendir, and all of the stat-related functions
- Phar::isBuffering — Used to determine whether Phar write operations are being buffered, or are flushing directly to disk
- Phar::isCompressed — Returns Phar::GZ or PHAR::BZ2 if the entire phar archive is compressed (.tar.gz/tar.bz and so on)
- Phar::isFileFormat — Returns true if the phar archive is based on the tar/phar/zip file format depending on the parameter
- Phar::isValidPharFilename — Returns whether the given filename is a valid phar filename
- Phar::isWritable — Returns true if the phar archive can be modified
- Phar::loadPhar — Loads any phar archive with an alias
- Phar::mapPhar — Reads the currently executed file (a phar) and registers its manifest
- Phar::mount — Mount an external path or file to a virtual location within the phar archive
- Phar::mungServer — Defines a list of up to 4 $_SERVER variables that should be modified for execution
- Phar::offsetExists — Determines whether a file exists in the phar
- Phar::offsetGet — Gets a PharFileInfo object for a specific file
- Phar::offsetSet — Set the contents of an internal file to those of an external file
- Phar::offsetUnset — Remove a file from a phar
- Phar::running — Returns the full path on disk or full phar URL to the currently executing Phar archive
- Phar::setAlias — Set the alias for the Phar archive
- Phar::setDefaultStub — Used to set the PHP loader or bootstrap stub of a Phar archive to the default loader
- Phar::setMetadata — Sets phar archive meta-data
- Phar::setSignatureAlgorithm — Set the signature algorithm for a phar and apply it
- Phar::setStub — Used to set the PHP loader or bootstrap stub of a Phar archive
- Phar::startBuffering — Start buffering Phar write operations, do not modify the Phar object on disk
- Phar::stopBuffering — Stop buffering write requests to the Phar archive, and save changes to disk
- Phar::uncompressAllFiles — Uncompresses all files in the current Phar archive
- Phar::unlinkArchive — Completely remove a phar archive from disk and from memory
- Phar::webPhar — mapPhar for web-based phars. front controller for web applications