Section 14--Namespace_PHP Tutorial
/*
+-------------------------------------------------- ----------------------------------+
| = This article is read by Haohappy<
| = Notes from the Chapter Classes and Objects
| = Translation + personal experience
| = To avoid possible unnecessary trouble, please do not reprint, thank you
| = We welcome criticisms and corrections, and hope to make progress together with all PHP enthusiasts!
| = PHP5 Research Center: http://blog.csdn.net/haohappy2004
+---------- -------------------------------------------------- ------------------+
*/
The namespace has been canceled in the official version of PHP5, and the content of this section is invalid--Haohappy note
Chapter Section 14 - Namespace
Naming variables, functions and classes is quite difficult. In addition to considering that the name of the variable should be easy to understand, you also have to worry about whether the name has been used somewhere else. In a short paragraph In scripts, the second question is fundamental. When you consider reusing your code, subsequent project code must avoid using the names you have used. Generally speaking, reusable code is always contained in a function or class , there are many possible naming conflicts that need to be dealt with. But naming conflicts can also occur between functions and classes. You can try to avoid this by prefixing all classes, or you can use a namespace statement. Namespace keyword names a block of code. Outside this block of code, the script must use the operator:: plus the name of the namespace to reference this block of code. The same method is used to reference static class members. Code within the namespace There is no need to declare a namespace, it is the default. This method is better than adding a prefix. Your code will become more compact and readable.
You may wonder whether it is possible to create hierarchical (embedded) ) namespace. The answer is no. But you can add a colon after the namespace name, and you can call variables, functions and classes that do not contain a colon in the name again. Colons are allowed in namespaces as long as they are not the first characters and the last character or followed by another colon. Colons in namespace names have no meaning to PHP, but if you use them to separate logical chunks, they can be a good indicator of what is going on in your code. The parent-child relationship.
/* Note: You can use this:
namespace animal:dog {}
namespace animal:pig {}
Use colons to illustrate the parent-child relationship .
*/
You may not include anything other than function, class or constant definitions within a namespace statement. This will prevent you from using them to improve older function libraries that use global variables. Namespaces are the most Suitable for object-oriented. Constants within a namespace use the same syntax as constants in a class.
Example 6.17 shows how to use a namespace.
Listing 6.17 Using a namespace
{
class textEngine
{ ($text)); $e = new textEngine;
return($e->uppercase($text));
$e = new core_php :utility::textEngine;
print($e->uppercase("from object") . "
");
//test function in namespace Test function in namespace
print(core_php:utility::uppercase("from function") . "
");
//bring class into global namespace Import class textEngine from core_php:utility;
$e2 = new textEngine;
?>
The Import statement imports a certain part of the namespace into the global namespace.
To import members of a single namespace, you can specify the type For constant, function or class, then write the name of the member;
//For example, import class XXX
If you want to import all members of a specific type, you can use * instead of the name;
/ /For example, import constant * imports all constants
If you want to import all members of all types, just use *.
//For example, import *
After the members, use the from keyword plus the namespace Name.
//For example, import class textEngine from core_php:utility;
In short, you have to write a statement like import * from myNamespace or import class textEngine from core_php:utility, just like in Example 6.17.
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/316928.html
TechArticle
/* +--------------------- -------------------------------------------------- --------+ |=This article is Haohappy's notes from the chapter ClassesandObjects when reading CorePHP Programming |=Translation is mainly + personal...

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



This article is reprinted from the WeChat public account "Living in the Information Age". The author lives in the information age. To reprint this article, please contact the Living in the Information Age public account. In machine learning, a basic concept is how to judge the difference between two samples, so that the similarity and category information between the two samples can be evaluated. The measure to judge this similarity is the distance between two samples in the feature space. There are many measurement methods based on different data characteristics. Generally speaking, for two data samples x, y, define a function d(x, y). If it is defined as the distance between the two samples, then d(x, y) needs to satisfy the following basic properties : Non-negativity: d(x, y)>=0 Identity: d(x, y)=0 ⇔ x=y pair

Swap space plays an important role in Linux systems, especially when the system is low on memory. It acts as a backup memory storage space that helps the system run smoothly and maintain stability even under high load. This article provides you with a detailed guide to adding swap space on Ubuntu 22.04LTS to ensure that your system performance is optimized and can handle various workloads. Understanding Swap Space Swap space provides virtual memory that is used to supplement the system's physical RAM. When the system is low on RAM, the kernel swaps data to disk to prevent out-of-memory and system crashes. Linux systems commonly use swap space to handle this situation. Run multiple memory-intensive applications simultaneously to process very large files or data

In C++ function naming, it is crucial to consider parameter order to improve readability, reduce errors, and facilitate refactoring. Common parameter order conventions include: action-object, object-action, semantic meaning, and standard library compliance. The optimal order depends on the purpose of the function, parameter types, potential confusion, and language conventions.

The remaining space on the c drive is 50-80G which is more suitable. Since the system will generate junk files, cache files, etc. in the future, it is recommended to reserve at least 50GB-80GB of space for the C drive; if you are not used to choosing a path when installing software and do not clean your computer frequently, then at least 100GB is required. .

As we all know, if the system disk occupied is too large after the system installation is completed, it may cause system lags, delays, and even file loss. Therefore, before you install the win11 system, you need to know how much C drive space is required to upgrade win11. Let’s take a look with the editor. How much C drive space is required to upgrade win11: Answer: Upgrading win11 requires 20-30GB of C drive space. 1. According to Microsoft’s win11 configuration requirements, you can see that win11 installation requires 64GB of hard drive space. 2. But in fact, generally speaking, there is no need for such a large space. 3. According to feedback from users who have already installed win11, the win11 upgrade requires about 20-30GB of C drive space. 4. But if our door only has

The Xbox console has a huge selection of games to download and play. Coupled with Microsoft's Xbox Game Pass subscription, the fun never stops with your game collection. However, there is the issue of space available for games, which is 356GB on Xbox Series S and 850GB on Xbox Series X. While this was fine in previous versions of the game, the maximum size of the game was probably between 20 and 45GB, which isn't the case with recent games. Recently available games end up taking up a lot of space on the disk, leaving us less space to download other games. ForzaHorizon5 and Halo5Guardians and more

If you have an iPhone 15 or iPhone 15 Pro Max, iOS 17.2 lets you record spatial video for viewing in the Photos app on Apple's upcoming Vision Pro headphones. Here's how you do it. Apple's VisionPro headphones are expected to be released around February 2024. Until then, one way you can prepare for this is to use your iPhone to record video in a special format called spatial video, which can be viewed on Apple's headphones. Spatial videos appear as normal videos when viewed on an iPhone, but they offer near three-dimensionality on VisionPro

1. Introduction Due to the explosive growth of current computer networks, the ensuing problem is the rapidly increasing number of network attacks. Various sectors of our society, from government departments to various critical infrastructures in society, are heavily dependent on computer networks and information technology. Apparently they are also vulnerable to cyberattacks. Typical network attacks disable the target computer, take services offline, or access the target computer's data. The number and impact of cyberattacks has increased significantly since the 1990s. Network security refers to a set of technologies used to protect network device activities and measures to protect them from all possible threats. In traditional network security technology, most of them are static access management, and the security control system will protect based on preset definitions.
