The namespace in PHP 5.3 is actually a good thing, which can simplify programming. Here are three types of methods to access classes in the namespace in the code
1 Reference namespace and classes
Assume that the namespace program is namespaced-class.php
namespace Christmas\DaysOf; class PartridgeInAPearTree{ }
include 'namespaced-class.php'; $bird1 = new Christmas\DaysOf\PartridgeInAPearTree(); var_dump($bird1);
2 Partial reference
include 'namespaced-class.php'; use Christmas\DaysOf; $bird2 = new DaysOf\PartridgeInAPearTree(); var_dump($bird2);
3 The simplest
include 'namespaced-class.php'; use Christmas\DaysOf\PartridgeInAPearTree as Bird; $bird3 = new Bird(); var_dump($bird3);
Related recommendations:
Detailed explanation of the steps to staticize the PHP page
The above is the detailed content of Three ways to use php namespace. For more information, please follow other related articles on the PHP Chinese website!