PHPDoc: Typehint in nested arrays (with e.g. 2 dimensions)

DerDu picture DerDu · Dec 12, 2013 · Viewed 8.5k times · Source

Is there a correct way to document values/objects in arrays which are within another dimension?

Normally an array will be handled like this:

/** @var ClassName[] $Array */
$Array = array( $InstanceOfClassName,.. )

But i need something like this:

/** @var ClassName[][] $Array */
$Array = array( 0 => array( $InstanceOfClassName,.. ) )

This is obviously not working, so what is the correct PHPDoc notation?

Answer

lisachenko picture lisachenko · Oct 21, 2014

PhpStorm allows to typehint nested arrays with double brackets [][]:

/** @var \SplFileInfo[][] $doubleNestedArray */
$doubleNestedArray = [[]];

$doubleNestedArray[0][1]->getFileInfo(); // ->getFileInfo() is suggested by IDE