PHP Tutorial-Alt Code Documentation
Documentation of PHP Tutorial-Alt Code by Doxygen
 All Files Functions Variables Pages
Global-scope statements and doxygen

Table of Contents

Summary

While global-scope statements work fine in PHP, you may not want to clutter the global scope with many statements. Also, doxygen does not expect global statements and can mis-identify parts of them (such as tagging some PHP keywords as variables). The solution is to put statements in functions, classes, namespaces, and modules rather than in global scope.

Details

For PHP itself, global-scope statements work fine. However, for long or complicated code, it may not be a good idea to have a lot of code at global-scope because of possible conflicts and other reasons. Using functions, classes, namespaces, and modules helps avoid global clutter.

There's also a useful documentation benefit for avoiding having most statements in global scope: if you use doxygen to generate your code doc, it will work better if most statements are in functions, classes, namespaces, and modules rather than in global scope. For example, an if ... else statement in global scope can cause doxygen to parse else as a variable instead of the PHP keyword that it is.