我对面向对象的 PHP 非常陌生。我只是写了一个代码来练习,但它显示错误,例如
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();