我很好奇为什么在类变量上使用范围解析运算符会导致致命的 php 错误,以及是否有解决方法。
例如:
<?php
class StaticTest
{
public static function output()
{
echo "Output called<br />";
}
}
Class Test
{
public $reference;
public function __construct()
{
$this -> reference = new StaticTest;
}
}
$static_test = new StaticTest;
$static_test::output(); //works as intended
$test = new Test;
$test -> reference::output(); //Unexpcted T_PAAMAYIM_NEKUDOTAYIM
$direct_reference = $test -> reference;
$direct_reference::output(); //works, closest solution i have found, but requires the extra line of code / variable
?>