我目前正在尝试打包库代码,然后将其发送给实际尝试使用该库代码的人.创建PHAR文件后,我正在尝试使用简单的测试脚本验证它是否已正确完成.在create-PHAR - > use-PHAR进程的某个时刻,我做错了什么.
如何正确创建,然后需要PHAR文件?
为了使PHAR的制作和验证变得简单,我将所有内容限制为问题的简化版本,但仍然无法继续.
这是我的文件:
~/phar-creation-and-require-test/
mylibrary.php
testoflibrary.php
make-phar.php
make-phar.sh
mylibrary.phar (after being created)
Run Code Online (Sandbox Code Playgroud)
mylibrary.php 内容:
<?
class FooClass {
private $foonum;
function FooClass() {
$this->foonum = 42;
}
}
?>
Run Code Online (Sandbox Code Playgroud)
make-phar.php 内容:
<?php
if ($argc < 3) {
print 'You must specify files to package!';
exit(1);
}
$output_file = $argv[1];
$project_path = './';
$input_files = array_slice($argv, 2);
$phar = new Phar($output_file);
foreach ($input_files as &$input_file) {
$phar->addFile($project_path, $input_file);
}
$phar->setDefaultStub('mylibrary.php');
Run Code Online (Sandbox Code Playgroud)
这叫做make-phar.sh:
#!/usr/bin/env bash …Run Code Online (Sandbox Code Playgroud) 到目前为止,我一直无法在官方PHP文档或本网站上找到此信息.所以,这可能意味着我在错误的条款下搜索,或者它不受支持.我在找什么?我会形容它......
假设我在PHP中进行了以下比较:
if (($a == $b) && ($b == $c))
doSomething();
else
doSomethingElse();
if (($d < $e) && ($e < $f))
doSomething();
else
doSomethingElse();
Run Code Online (Sandbox Code Playgroud)
PHP是否有某种语法将比较链接在一起而没有两种不同比较的显式AND?例如,这样的事情是可能的:
if ($a == $b == $c)
doSomething();
else
doSomethingElse();
if ($d < $e < $f)
doSomething();
else
doSomethingElse();
Run Code Online (Sandbox Code Playgroud)
请注意,我正在寻找语言的句法速记.我知道我可以轻松地为这些链式比较中的每一个编写函数,但这是一个笨拙的解决方法,并不是所希望的.例如:
function chainedGreaterThan($args)
{
for ($i = 0; $i < count($args) - 1; $i++)
if ($args[$i] <= $args[$i + 1])
return false;
return true;
}
Run Code Online (Sandbox Code Playgroud)
这在技术上是可行的,但不是语言给出的语法简写.