Blog

Categories:

'Strict Mode' in PHP7 Is Not Strict Enough?

Recently I heard that in PHP7 we can pass a string as integer and get result in strict mode. Let’s try it together. Pay attention, behavior we check is already described in the documentation. It’s all being ‘not a bug, just a feature’. So, let’s go. As you know, now we can define strict mode using next instruction:

declare(strict_types=1);

So, try to write simple piece of code like this:

<?php
declare(strict_types=1);

function typesCheck(int $number) {
	echo $number;
	return $number;
}

typesCheck(3);

And now we will see ‘3’ on our screen. It’s absolutely predictable behavior. Now we will try to pass a wrong argument:

Read More