1
例子:如何get_class()與範圍解析運算符在PHP中?
<?php
class X {
function foo() {
echo "Class Name:".get_class($this)."<br>";
echo get_class($this)::$private_var; //not working
echo Y::$private_var; //works
Y::y_method(); //works
get_class($this)::y_method(); //not working
}
function bar() {
$this->foo();
}
}
class Y extends X {
public static $private_var = "Variable of Y Class";
public function y_method()
{
echo "Y class method";
}
}
$y = new Y();
$y->bar();
?>
有些身體請幫忙,爲什麼我不能使用get_class()和(::)運算符。 – hardik