Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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__ . "
"; ?>
this will print empty string
when this file is included in another namespace
Example
#test2.php
<?php
namespace testspace {
include 'test1.php';
echo __NAMESPACE__ . "
";
}
?>
Output
This will print following output
testspace
Advertisements