

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP Global space
Introduction
In absence of any namespace definition, all definitions of class, function etc. are placed in a global namespace. If a name is prefixed with \ , it will mean that the name is required from the global space even in the context of the namespace.
Using global space specification
Example
<? namespace test; /* This function istest\fopen */ function fopen() { /* ... */ $f = \fopen(...); // call global fopen return $f; } ?>
Included files will default to the global namespace.
Example
#test1.php <?php echo __NAMESPACE__ . "\n"; ?>
this will print empty string
when this file is included in another namespace
Example
#test2.php <?php namespace testspace { include 'test1.php'; echo __NAMESPACE__ . "\n"; } ?>
Output
This will print following output
testspace
- Related Questions & Answers
- PHP Accessing Global classes
- How to declare a global variable in PHP?
- JavaScript global Property
- Global variables in Java
- Global keyword in Python
- What is Global Scheduling?
- What is Global Marketing?
- Remove new lines from a string and replace with one empty space PHP?
- Global System for Mobile Communications
- Global keyword in Python program
- Global Scope Variables in Postman?
- Global Variables in Lua Programming
- What are global variables in C++?
- Global and Local Variables in C#
- Global and Local Variables in Python?
Advertisements