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 map creates a new map using values from the current instance and another mapphp svn 函数 creates a new empty file returns true if all is ok false otherwisephp com 函数 convert a variant into a new variant object of another typephp 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 instructs phar to intercept fopen file get contents opendir and all of the stat related functionsphp 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 returns the full path on disk or full phar url to the currently executing phar archivephp phar set the alias for the phar 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 pharfileinfo returns the actual size of the file with compression inside the phar archivephp swoole client redirect the data to another file descriptor.php ziparchive adds a file to a zip archive from the given path
关注编程学问公众号