Register now or log in to join your professional community.
Type declarations (or type hints) allow functions to require that parameters are of a certain type at call time. If the given value is of the incorrect type, then an error is generated: in PHP 5, this will be a recoverable fatal error, while PHP 7 will throw a TypeError exception.
To specify a type declaration, the type name should be added before the parameter name. The declaration can be made to accept NULL values if the default value of the parameter is set to NULL.
source: http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration
Type hinting means that whatever you pass must be an instance of (the same type as) the type you're hinting.
"Type hinting" forces you to only pass objects of a particular type. This prevents you from passing incompatible values, and creates a standard if you're working with a team etc.
Since PHP 5 you can use type hinting to specify the expected data type of an argument in a function declaration. ... By telling PHP exactly what kind of objects the enroll() method expects to receive, you can ensure that students are being enrolled in a school instead of a nunnery or a 401K.
you can use type hinting to specify the expected data type of an argument in a function declaration. When you call the function, php will check whether or not the arguments are of the specified type. If not, the run-time will raise an error and execution will be halted.