我看了一下,试过但我找不到答案。调用没有对象实例化的类方法(带构造函数)在php
在PHP中,是否有可能在不实例化对象的情况下调用类的成员函数(当该类需要构造函数来接收参数时)?
A码的例子(其给出错误):
<?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");
?>
我想回声测试:: __结构( “世界”)::警报( “你好”);可能工作,但它不,叹息 – mykchan 2010-06-23 04:07:36
使alert()静态函数将完成这项工作。 – 2014-02-25 10:10:42