__construct
Note
This is a point-in-time snapshot of the API documentation from January 2026. Going forward, we will not be maintaining a public copy of these references, and recommend users to refer to the built-in signature helpers available in the Hack LSP instead for complete and up-to-date information.
Creates a Map from the given KeyedTraversable, or an empty Map if
null is passed
public function __construct(
?KeyedTraversable<Tk, Tv> $iterable = NULL,
): void;
Parameters
?KeyedTraversable<Tk,Tv> $iterable = NULL
Returns
void
Examples
This example shows how to create a Map from various KeyedTraversables:
// Create a new string-keyed Map from an associative array
$m = new Map(darray[
'red' => '#ff0000',
'green' => '#00ff00',
'blue' => '#0000ff',
'yellow' => '#ffff00',
]);
\var_dump($m);
// Create a new integer-keyed Map from a Vector
$m = new Map(Vector {'red', 'green', 'blue', 'yellow'});
\var_dump($m);
This example shows how passing null to the constructor creates an empty Map:
// An empty Map is created if null is provided
$m = new Map(null);
\var_dump($m);