Encoding declaration pragma must be¶
Description¶
The declare(encoding = ...) pragma sets the source encoding PHP uses to parse the rest of the script, so, like strict_types, it has to be known before anything else in the file is compiled. It must therefore be the very first statement in the script, exactly like the strict_types declaration.
The full message reads: Encoding declaration pragma must be the very first statement in the script. In practice, this directive only has an effect when the zend.multibyte ini setting is enabled; otherwise it is silently ignored, but the placement rule is still enforced.
Example¶
<?php
echo 'Hello';
declare(encoding = 'ISO-8859-1');
?>
Literal Examples¶
Encoding declaration pragma must be the very first statement in the script
Solutions¶
Move the
declare(encoding = ...)statement to be the very first statement in the file.Remove any characters or statements placed before the opening
<?phptag.
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>`_.