Coercive and strict modes
Type definitions give our code the guarantee that parameter and return types will be correct. They can operate in two modes. Coercive – the default – is basically as if a manual type cast is called on each parameter at the top of the function, and the return parameter before the variable is returned. This brings back a lot of the type-juggling pain and uncertainty we are trying to avoid.
The other approach, and the one I suggest you use, is strict. In strict mode, PHP will spit its dummy out (throw an exception) at the first sign of your code being misused (by you, no doubt). This early and robust failure allows you to quickly find issues in your code without having to wait for bugs to occur and then figuring out that the cause of the bug is an invalid value being passed further up the call chain.
To enable strict mode, you must include declare(strict_types=1);
at the top of your PHP file. You have probably noticed that this is done in...