Three methods to use phpnamespace namespace in PHP5.3 is actually a good thing, which can simplify programming. The following describes three methods to access classes in namespace in code. Method 1 references namespace and classes & nbsp; assume that the namespace program has three methods to use php namespace.
The namespace in PHP 5.3 is actually a good thing, which can simplify programming. the following introduces three types
Methods for accessing classes in namespace
1 Reference namespace and class
Assume that the namespace program is a namespaced-class.php
Namespace Christmas \ DaysOf;
Class PartridgeInAPearTree {
}
Reference method:
Include 'namespaced-class. php ';
At this time, the complete namespace and the following classes are introduced in NEW.
2 Part references
Include 'namespaced-class. php ';
Use Christmas \ DaysOf;
$ Bird2 = new DaysOf \ PartridgeInAPearTree ();
Var_dump ($ bird2 );
After the namespace is specified in USE, you only need to reference the last part of the namespace Daysof.
3. simplest
Include 'namespaced-class. php ';
Use Christmas \ DaysOf \ PartridgeInAPearTree as Bird;
$ Bird3 = new Bird ();
Var_dump ($ bird3 );
The specified class in the namespace is replaced by a custom name, which is very convenient.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.