+ 2

Type Declaration

I just love this TypeError and I want to share it with you. https://code.sololearn.com/wgujdsCeF1QM/?ref=app

7th Oct 2017, 1:25 AM
Freezemage
Freezemage - avatar
6 Respuestas
+ 2
It happens because all of PHP data types are instances of interfaces, which implement those types. When I pass an argument to a function, PHP checks, if this argument is an instance of 'boolean', and if so - proceeds to the function's body, an if it's not - throws exception 'TypeError' showing needed data type and data type passed as an argument, which stops the script. The interface for data type 'boolean' is called 'bool', so it looks like this: echo test(bool true); PHP checks if true is an instance of 'boolean', but it is not, and throws exception. But in some parts of PHP core the 'bool' type is called 'boolean', like in this TypeError exception. That's why it looks like this.
7th Oct 2017, 1:48 AM
Freezemage
Freezemage - avatar
+ 2
lmfao
7th Oct 2017, 1:38 AM
LunarCoffee
LunarCoffee - avatar
+ 2
Thanks for the explanation. Great example.
7th Oct 2017, 1:54 AM
Kirk Schafer
Kirk Schafer - avatar
+ 2
For this and more PHP badness, I can't recommend this article enough: https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/ Also www.phpwtf.org
7th Oct 2017, 2:43 AM
Schindlabua
Schindlabua - avatar
0
Interesting.
7th Oct 2017, 1:50 AM
LunarCoffee
LunarCoffee - avatar
0
don't know
7th Oct 2017, 3:04 PM
Reem