据我所知,php getcwd()(和类似的函数dirname(__FILE__))应该返回正在执行的文件的当前目录.
如果当前目录恰好是另一个目录的符号链接,则php(可能与apache一起)应该返回显示符号链接名称的路径作为您所在的"目录".
例:
from /var/www,
directory 'one' contains index.php
symlink 'two' points at directory 'one'
one/index.php: <?php echo getcwd(); ?>
Run Code Online (Sandbox Code Playgroud)
在浏览器中访问http://localhost/two/index.php显示/var/www/one.
我希望它能显示出来 /var/www/two
有谁知道这是一个php或apache设置我可以改变吗?或者我不能以这种方式使用符号链接?
我看了又试过但我找不到答案.
在PHP中,是否可以调用类的成员函数(当该类需要构造函数来接收参数时)而不将其实例化为对象?
一个代码示例(给出错误):
<?php
class Test {
private $end="";
function __construct($value) {
$this->end=$value;
}
public function alert($value) {
echo $value." ".$this->end;
}
}
//this works:
$example=new Test("world");
$example->alert("hello");
//this does not work:
echo Test("world")::alert("hello");
?>
Run Code Online (Sandbox Code Playgroud)