English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
1.The namespace declaration must be the first statement in the program script.In addition, all non-PHP code including whitespace cannot appear before the namespace declaration.
Below is an example of an error:
<html> <?php namespace MyProject; // Fatal error - The namespace must be the first statement in the program script ?>
This is also wrong
<?php // Lots // of // interesting // comments and white space namespace Foo; class Bar { } ?>
2.Cannot use PHP keywords.
Below is an example of an error:
<?php namespace Project;/Classes/Function; // Causes parse errors namespace Project;/Abstract/Factory; // Causes parse errors ?>
3.Constants defined in the namespace.
The following MESSAGE is in the global namespace:
<?php namespace test; define('MESSAGE', 'Hello world!'); ?>
Define2Constants defined in the test namespace:
<?php namespace test; define('test\HELLO', 'Hello world!'); define(__NAMESPACE__ . '\GOODBYE', 'Goodbye cruel world!'); ?>
This is the full content of the brief discussion on the points to note when defining the command space in PHP (recommended) brought to you by the editor. I hope everyone will support and cheer for the tutorial~