When working on the following code, I noticed that declare (strict_types = 1) does not affect the arguments to the callback function via array_walk ()
<?php
declare(strict_types=1);
function myCallBack(int $value, $key) {
echo $value;
}
function myFunc(int $value, $key) {
echo $value;
}
$myArr = array("eggs" => 4, "Butter" => 4, "meat" => 4.5);
echo 'myCallBack..';
array_walk($myArr, 'myCallBack');
echo ' <br />myFunc..';
myFunc(4.2, 'eggs');
?>
I expect php to throw an exception instead of 444 because the [meat] value in $ myArr is not an integer!
Apparently php ignores the fact that [meat] in $ myArr is a float for some reason! instead of throwing an exception, just like with myFunc ().
Is this normal php behavior or am i missing something?
source
share