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 : Disjunctive Normal Form (DNF), False, Mixed, Never Type, Nullable, Object, Properties, Return Type, strict_types, True, Property Type Declaration, Typed Property, Intersection Type, Object Type, Scalar Types, Special Types, Union Type, Variables
Added in PHP 7.0