Created
July 21, 2023 07:55
-
-
Save integer/4f982f836b486ce16964197aec94ee3c to your computer and use it in GitHub Desktop.
PHP declare(strict_types=1) trap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// No strict type here... | |
require_once __DIR__ . '/strict.php'; | |
function foo(/* int */ $input) { // ..so adding type definition is safe, isn't it? | |
printf("param=%d\n", $input); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
foo(5); | |
foo('7'); // but it fails, because it is called from file with declare(strict_types=1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment