我希望我的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