我希望我的PHP IDE(NuSphere PhpEd)能够检测到我的二维数组元素(一个对象)的属性,该属性在我键入右后没有显示出来箭头在我的IDE。PHP 7数组 - 检测二维数组元素的属性
有什么办法在PHP 7中自动生成多维数组元素属性的建议,其中每个元素是具有某些属性的对象?
<?php
class Cell
{
private $color;
public function __construct()
{
$this->color = "red";
}
public function __get($propertyName)
{
if ($propertyName == 'color')
return $this->color;
}
public function __set($propertyName, $value)
{
if ($propertyName == 'color')
$this->color = $value;
}
}
class Matrix implements ArrayAccess
{
private $matrix = array();
public function __construct($maxX, $maxY)
{
$this->matrix = array_fill(1, $maxX, array_fill(1, $maxY, null));
}
public function &offsetGet($name)
{
return $this->matrix[$name];
}
public function offsetSet($name, $value)
{
$this->matrix[$name] = $value;
}
public function offsetExists($name)
{
return isset($this->matrix[$name]);
}
public function offsetUnset($name)
{
unset($this->matrix[$name]);
}
}
$matrix = new Matrix(3,3);
for ($xIdx = 1; $xIdx <= 3; $xIdx++)
for ($yIdx = 1; $yIdx <= 3; $yIdx++)
$matrix[$xIdx][$yIdx] = new Cell();
$matrix[2][2]->color = "green";
echo $matrix[2][2]->color;
?>
您正在进入phpdoc的领域,这是一种技术,它允许您提供该类型的信息。 – Marty
感谢您的回复,您是否偶然会有一个例子,说明我在输入箭头时如何看到在phpdoc建议的属性列表中? – Vahe
当然,完成了。 – Marty