Are object
and array
really the only types allowed for type hinting?
Plus, they state in documentation that standard types string
and int
cannot be type hinted also.
And that makes me more curious. What is the reason behind only allowing two type hints and the dropping of standard ones?
Thanks in advance!
PHP 5.3 currently supports only array
and ClassName
typehints.
The upcoming PHP 5.4 version will also support callable
typehints.
The reason why scalar typehints are currently not supported is that their behavior in a weakly typed language is unclear:
1
and '1'
? -> Against PHP spirit'hallo'
would give 0
for an int
typehint -> UnintuitiveThat's the reason why the scalar typehint implementation was backed out of PHP 5.4 - there was no consensus on this question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With