Skip to content

Instantly share code, notes, and snippets.

@integer
Created July 21, 2023 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save integer/4f982f836b486ce16964197aec94ee3c to your computer and use it in GitHub Desktop.
Save integer/4f982f836b486ce16964197aec94ee3c to your computer and use it in GitHub Desktop.
PHP declare(strict_types=1) trap
<?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);
}
<?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