Fatal error: strict_types declaration must be the very first statement in the script in... (PHP7)

Asked

Viewed 370 times

0

I’m studying PHP and can’t identify the cause of this error: "Fatal error: strict_types declaration must be the very first statement in the script in C: Users Fernando Onedrive_development_projet PHP index.php on line 8"

<!DOCTYPE html>
<html>
<head>
   <meta charset="UTF-8">
   <title>Index - PHP</title>
</head>
<body>
<?php declare(strict_types=1);
    function soma($x, $y){
        $z = $x + $y;
        return $z;
    }   
?>
</body>
</html>

Could someone give me a hand, please? :)

  • Try to put the declare(strict_types=1); as the first thing in the archive.

  • I do not understand, I must define "declare()" elsewhere in the scope?

  • In the same file, in the first row: https://pastebin.com/bPfxbGJa

  • Same error, but points to the first line: **"Fatal error: strict_types declaration must be the very first statement in the script in C: Users Fernando Onedrive_development_projet PHP index.php on line 1"**

  • Here it worked. PHP 7.2. Is your file UTF8? If so, it should be without GOOD

  • However, how do I solve this problem?

  • Exactly as I said. UTF8 file cannot have BOM. On Notepad++ you have the option in the Format to UTF8 menu without BOM: https://www.phpbb.com/kb/images/585_encoding.jpg

  • Said and done, it worked @lcssanches, thank you very much!

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.