Home  >  Article  >  Backend Development  >  PHP创建phar文档,有很多不明白的地方,运行报错

PHP创建phar文档,有很多不明白的地方,运行报错

WBOY
WBOYOriginal
2016-06-06 20:43:071372browse

我想把index.php这个文件打包成phar文档:
其文件组织是这样的:
PHP创建phar文档,有很多不明白的地方,运行报错
index.php与1.php在同一个目录。
index.php 里面只有一个hello world
然后在1.php里面代码是这样的:

<code class="lang-php"><?php /**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2014/9/16
 * Time: 21:45
 */

$phar = new Phar('user.phar', 0, 'user.phar');
$phar->buildFromDirectory(dirname(__FILE__) . '/index.php');
$phar->setStub($phar->createDefaultStub('1.php', '1.php'));
$phar->compressFiles(Phar::GZ);
</code>

运行结果报错了:
PHP创建phar文档,有很多不明白的地方,运行报错
为啥会错呢?
$phar->setStub($phar->createDefaultStub('1.php', '1.php'));参数错了吗?
这个stub是个啥东西?
这个1.php是直接运行就可以了还是使用php命令行 运行呢?
求大神解答

回复内容:

我想把index.php这个文件打包成phar文档:
其文件组织是这样的:
PHP创建phar文档,有很多不明白的地方,运行报错
index.php与1.php在同一个目录。
index.php 里面只有一个hello world
然后在1.php里面代码是这样的:

<code class="lang-php"><?php /**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2014/9/16
 * Time: 21:45
 */

$phar = new Phar('user.phar', 0, 'user.phar');
$phar->buildFromDirectory(dirname(__FILE__) . '/index.php');
$phar->setStub($phar->createDefaultStub('1.php', '1.php'));
$phar->compressFiles(Phar::GZ);
</code>

运行结果报错了:
PHP创建phar文档,有很多不明白的地方,运行报错
为啥会错呢?
$phar->setStub($phar->createDefaultStub('1.php', '1.php'));参数错了吗?
这个stub是个啥东西?
这个1.php是直接运行就可以了还是使用php命令行 运行呢?
求大神解答

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn