Search code examples
phpphp-7phpdoc

type hinting array with 2 entries / phpdoc for array


say i have this

function foo(){
   return [1, 'bippo'];

}

how can I write phpdoc that it creates automatically on autocomplete something like this

list($x, $y) = foo();

Solution

  • As stated in the phpDocumentor: Defining a 'Type' section Array you can specify an array containing multiple types as @return (int|string)[], which means that the return type of this function is an array that can contain elements which are either of type int or string