Type System¶
Type declarations can be added to function arguments, return values, and, as of PHP 7.4.0, class properties. They ensure that the value is of the specified type at call time, otherwise a TypeError is thrown.
<?php
function foo(A $a) : void {}
class x {
private A $p;
}
?>
See also Explore Your Types, Narrowing types for static analysis
Related : Scalar Types, Union Type, Intersection Type, Special Types, Disjunctive Normal Form (DNF)
Added in PHP 7.0