i 正在测试关于如何准确开展工作的《法定关键词》,而在此之前,人们不了解正在发生的情况。
审议两个类别:<代码>ClassNameA &ClassNameB
和以下代码。
<>ClassName 无法定关键词
class ClassNameA
{
private $name;
public function __construct($value) {
if($value != ) {
$this->name = $value;
}
$this->getValue();
}
public function getValue() {
echo $this->name;
}
}
<>ClassNameB with Static Keyword
class ClassNameB
{
private static $name;
public function __construct($value) {
if($value != ) {
self::$name = $value;
}
$this->getValue();
}
public function getValue() {
echo self::$name;
}
}
多次使用NameA类
$a = new ClassNameA(12);
echo <br/> ;
$a = new ClassNameA(23);
echo <br/> ;
$a = new ClassNameA( ); //Argument given is Empty here
它的产出是:
12
23
现在使用NameB级的多次瞬时发射物体
$a = new ClassNameB(12);
echo <br/> ;
$a = new ClassNameB(23);
echo <br/> ;
$a = new ClassNameB( ); //Argument given is Empty here
产出如下:
12
23
23
Note the extra value 23 it is taking even if the Argument Passed is Empty. Is this a bug? or am i missing something?