I'm writing a command line PHP script with PHP7.
When I put the shebang (#!/usr/bin/php
) on top of the file, if I add the strict mode with declare(strict_types=1)
, I get the following error :
PHP Fatal error: strict_types declaration must be the very first statement in the script in index.php on line 3
The only way I found to get the strict types working is to remove the shebang line.
Is there a way to use both shebang and strict types or it is a php bug ?
Ok so here is the reason why the strict types declaration did not work : i had a new line between the shebang and the php opening tag.
working example :
#!/usr/bin/php
<?php
declare(strict_types=1);
// your code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With