Phar::copy

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

Phar::copyCopy a file internal to the phar archive to another new file within the phar

说明

public Phar::copy ( string $oldfile , string $newfile ) : bool

Note:

此方法需要 将 php.ini 中的 phar.readonly 设为 0 以适合 Phar 对象. 否则, 将抛出PharException.

Copy a file internal to the phar archive to another new file within the phar. This is an object-oriented alternative to using copy() with the phar stream wrapper.

参数

oldfile

newfile

返回值

returns TRUE on success, but it is safer to encase method call in a try/catch block and assume success if no exception is thrown.

错误/异常

throws UnexpectedValueException if the source file does not exist, the destination file already exists, write access is disabled, opening either file fails, reading the source file fails, or a PharException if writing the changes to the phar fails.

范例

Example #1 A Phar::copy() example

This example shows using Phar::copy() and the equivalent stream wrapper performance of the same thing. The primary difference between the two approaches is error handling. All Phar methods throw exceptions, whereas the stream wrapper uses trigger_error().

<?php
try {
    
$phar = new Phar('myphar.phar');
    
$phar['a'] = 'hi';
    
$phar->copy('a''b');
    echo 
$phar['b']; // outputs "hi"
} catch (Exception $e) {
    
// handle error
}

// the stream wrapper equivalent of the above code.
// E_WARNINGS are triggered on error rather than exceptions.
copy('phar://myphar.phar/a''phar//myphar.phar/c');
echo 
file_get_contents('phar://myphar.phar/c'); // outputs "hi"
?>

相关文章
php svn 函数 creates a new empty file returns true if all is ok false otherwisephp postgresql pdo copy data from table into filephp phar construct a phar archive from the files within a directoryphp phar convert a phar archive to a non executable tar or zip filephp phar convert a phar archive to another executable phar archive file formatphp phar copy a file internal to the phar archive to another new file within the pharphp phar returns the number of entries files in the phar archivephp what makes a phar a phar and not a tar or a zip? phar file stubphp phar returns phar gz or phar bz2 if the entire phar archive is compressed .tar.gz/tar.bz and so on php phar returns true if the phar archive is based on the tar/phar/zip file format depending on the parameterphp phar mount an external path or file to a virtual location within the phar archivephp phar set the contents of an internal file to those of an external filephp phar set the alias for the phar archivephp phardata add a file from the filesystem to the tar/zip archivephp phardata convert a phar archive to a non executable tar or zip filephp phardata copy a file internal to the phar archive to another new file within the pharphp phardata delete a file within a tar/zip archivephp phardata set the contents of a file within the tar/zip to those of an external file or stringphp pharfileinfo returns the actual size of the file with compression inside the phar archivephp ziparchive adds a file to a zip archive from the given path
关注编程学问公众号