strict_types declaration must be

Description

This is the same placement rule documented in full under strict_types declaration must be the very first statement in the script: the declare(strict_types = ...) pragma changes how the whole file is compiled, so PHP must see it before compiling anything else. Here, the namespace statement, itself harmless, is still a statement, and it pushes the declare() out of first position.

Only a preceding declare() call (for ticks or encoding) is tolerated before it; any other statement is not.

Example

<?php

namespace App;

declare(strict_types = 1);

?>

Literal Examples

  • strict_types declaration must be the very first statement in the script

Solutions

  • Move the declare(strict_types = 1) statement to be the very first statement in the file.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.