【发布时间】:2016-01-02 10:25:22
【问题描述】:
我刚刚写了一个示例类来更好地理解 PHP 中的静态方法和变量。我了解静态变量的工作原理,但静态函数没有按预期工作。如果你看到下面的代码
class Car{
static $wheels=4;
static function getWheels(){
echo Car::$wheels=10;
}
}
$car1 = new Car();
$car1->getWheels();
我期待
$car1->getWheels(); to throw and error since getWheels is a static method.
为什么这不会引发错误或警告?
【问题讨论】: