PHP Doku:: Construct a Phar archive object - phar.construct.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzErweiterungen zur Datenkompression und ArchivierungPharThe Phar classPhar::__construct

Ein Service von Reinhard Neidl - Webprogrammierung.

The Phar class

<<Phar::compressFiles

Phar::convertToData>>

Phar::__construct

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

Phar::__constructConstruct a Phar archive object

Beschreibung

void Phar::__construct ( string $fname [, int $flags [, string $alias ]] )

Parameter-Liste

fname

Path to an existing Phar archive or to-be-created archive

flags

Flags to pass to parent class RecursiveDirectoryIterator.

alias

Alias with which this Phar archive should be referred to in calls to stream functionality.

Fehler/Exceptions

Throws BadMethodCallException if called twice, UnexpectedValueException if the phar archive can't be opened.

Beispiele

Beispiel #1 A Phar::__construct() example

<?php
try {
    
$p = new Phar('/path/to/my.phar'CURRENT_AS_FILEINFO KEY_AS_FILENAME,
                  
'my.phar');
} catch (
UnexpectedValueException $e) {
    die(
'Could not open my.phar');
} catch (
BadMethodCallException $e) {
    echo 
'technically, this cannot happen';
}
// this works now
echo file_get_contents('phar://my.phar/example.txt');
// and works as if we had typed
echo file_get_contents('phar:///path/to/my.phar/example.txt');
?>


2 BenutzerBeiträge:
- Beiträge aktualisieren...
myselfasunder at findmenow dot gmail dot com
12.07.2010 22:18
Zip support seems to be shaky, in that just attempting to open a Zip file (created by 7-Zip) with both the 'zlib' and 'zip' extensions enabled renders the following error:

Error: Cannot convert phar archive "C:/Development/webdir/public_html/TestPhar.zip", unable to open entry "TestPhar/" contents: phar error: internal corruption of zip-based phar "C:/Development/webdir/public_html/TestPhar.zip" (local header of file "TestPhar/" does not match central directory)

Stick to GZ's and BZ2's (but don't forget to enable the BZ2 extension if necessary).

Phar can ONLY open executable Phar's and PharData can ONLY open non-executable Phar's. Both have the ability to convert between the two formats.

However, you can reference a file within a Phar regardless of whether it's executable using the Phar stream wrapper (file_get_contents('phar://<Phar file>/subdirectory/subdirectory/somefile.txt')).

Dustin Oprea
Christian
13.04.2010 15:39
It's not possible to create a new archive when safe_mode is enabled! You simply return a 'Phar creation or opening failed' error.
This applies to Phar and PharData in PHP 5.3.2.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)