Cannot mix bracketed namespace declarations¶
Description¶
PHP supports two syntaxes to declare a namespace: the unbracketed form, namespace Foo;, which applies to the rest of the file (or until the next namespace statement), and the bracketed form, namespace Foo { ... }, which delimits the namespace explicitly.
A single file must consistently use one form or the other; mixing bracketed and unbracketed declarations together is not allowed. The full message reads: Cannot mix bracketed namespace declarations with unbracketed namespace declarations.
Example¶
<?php
namespace A {
// bracketed syntax
}
namespace B;
// unbracketed syntax, in the same file
?>
Solutions¶
Convert every
namespacestatement in the file to the bracketed form.Convert every
namespacestatement in the file to the unbracketed form.Split the file so that each file only uses one of the two forms.
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>`_.