Worth noting that if you add the declare(strict_types=1) (since PHP 7.0.0) declaration at the top of your PHP script, integers wont coerce with floats and instead will throw an error as expected.
<?php// https://repl.it/repls/OpenRowdyTrialsdeclare(strict_types=1);functiona(int$b){return$b;}var_dump(a(1.1));// PHP Fatal error: Uncaught TypeError: Argument 1 passed to a() must be of the type integer, float given
I like to build cool things, work with nice people and help others where I can. Currently I'm an engineering manager for a fintech startup and historically a serial founder & freelancer software dev.
Location
München, Deutschland 🇩🇪
Education
The Open University
Work
Engineering Manager @ Deutsche Fintech Solutions GmbH
Good to know, thanks! Interesting it isn't the default behaviour though but I assume this can be set in the .ini or elsewhere to be defaulted. I will look into that but either way, thanks for sharing!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Worth noting that if you add the
declare(strict_types=1)
(since PHP 7.0.0) declaration at the top of your PHP script, integers wont coerce with floats and instead will throw an error as expected.Good to know, thanks! Interesting it isn't the default behaviour though but I assume this can be set in the
.ini
or elsewhere to be defaulted. I will look into that but either way, thanks for sharing!