User Contributed Notes 10 notes

using of global namespaces and multiple namespaces in one PHP file increase the complexity and decrease readability of the code.Let's try not use this scheme even it's very necessary (although there is not)

If you have the habit to always use the closing PHP tag "?>" in your test files, remember that with the bracketed syntax code outside the brackets, including new lines outside the PHP tags, is not allowed. In particular, even though PHP sees a new line after the closing tag as a part of the line and eats it, some editors, such as Gedit, Gvim, Vim and Nano in Ubuntu, will add yet another new line after this new line and this will create an error.

There are rational examples of where the ability to blend multiple namespaces into a single file is not only desirable but also absolutely necessary. An example of where this ability is useful is over in the very popular phpseclib library where they are PSR-4 compliant but, in order to be compliant, they have to read a directory of files to know what classes are available so that the autoloader can load the correct files. If they, instead, just bundled the defaults into one file using this mechanism already supported by PHP core, there would be no need to do extraneous scanning of the file system.

That's just one legitimate use-case where strict compliance with PSRs gets in the way of good software development.

With the bracketed syntax, a simple white space after the closing "?>" of the file, even a new line that is some times considered as the end of a line and thus a part of the line, will (at the least in some php installations) be considered as code outside the brackets and will result in an error. It's general good practice to avoid white space after the closing "?>". Just pointing out that it is another case where it matters.