我对面向对象的PHP很新颖。 我只是写了代码练习,但它显示错误,如PHP示波器分辨率运算符:此代码显示很多错误,由于第10行代码
Notice: Undefined variable: type in F:\xampp\htdocs\testing\scope.php on line 10
Notice: Undefined index: in F:\xampp\htdocs\testing\scope.php on line 10
我认为它是因为$type
这个错误就要来了。有人可以帮忙吗?提前致谢。
class Lookup {
public static $items = array();
public $x = '34';
public $y = '26';
public static function setItems($items, $x, $y) {
$items[$type] = array(
'x' => $this->x,
'y' => $this->y);
}
public static function getSum() {
$z = self::$items[$type]['x'] + self::$items[$type]['y'];
return $z;
}
}
echo Lookup::getSum();
'$ type'从哪里来?这不是一个OOP问题。 –
你使用哪个PHP版本? [*后期静态绑定*](http://php.net/manual/language.oop5.late-static-bindings.php)5.3中介绍的 –
乔治说这不是一个面向对象的问题。代码中的'$ type'变量在这里不存在! –