With Type hinting we can specify the expected data type (arrays, objects, interface, etc.) for an argument in a function declaration. This practice can be most advantageous because it results in better code organization and improved error messages.
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.
- Typehints can be optional
- Type hints can be reference
- Typehints parameters can default to NULL.
- Type hints class does not have to be defined when a function definition is parsed
- Objects need not be of the same class to satisfy typehinting.
- Type hints can be PHP scalar value