- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
PHP Name Resolution Rules
In a PHP code, appearance of namespace is resolved subject to following rules −
A namespace identifier without namespace separator symbol (/) means it is referring to current namespace. This is an unqualified name.
If it contains separator symbol as in myspace\space1, it resolves to a subnamespace space1 under myspace. Such type of naming is relative namespace.
Name of fully qualified namespace starts with \ character. For example, \myspace or \myspace\space1.
Fully qualified names resolve to absolute namespace. For example \myspace\space1 resolves to myspace\space1 namespace
If the name occurs in the global namespace, the namespace\ prefix is removed. For example namespace\space1 resolves to space1.
However, if it occurs inside another namespace, it is treated differently. For example, if namespace\space1 is inside myspace, it is equivalent to myspace\space1
First segment of the name in qualified name is translated according to the current class/namespace import table.
If no import rule applies, the current namespace is prepended to the name.
class-like names are translated according to the class/namespace import table, function names according to the function import table and constants according to the constant import table.
For unqualified names, if no import rule applies and the name refers to a function or constant and the code is outside the global namespace, the name is resolved at runtime. First it looks for a function from the current namespace, then it tries to find and call the global function.
- Related Articles
- PHP Scope Resolution Operator (::)
- How to get or set the resolution of an image using imageresolution() function in PHP?
- What is a DNS Name Resolution and explain the cache poisoning attack in DNS?
- C++ Scope resolution operator
- Scope resolution operator in C++
- Alternative Dispute Resolution: Meaning & Significance
- How to validate domain name in PHP?
- What is Address Resolution Protocol (ARP)?
- Some CSS Rules
- Paragraphs: Definition & Rules
- Mines Rules, 1955
- How to get current function name in PHP?
- What is Reverse Address Resolution Protocol (RARP)?
- Change the resolution of analogRead in Arduino