downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

Usar espacios de nombres: una alternativa a funciones/constantes globales> <Usar espacios de nombres: Apodar/Importar
[edit] Last updated: Fri, 17 May 2013

view this page in

Espacio global

(PHP 5 >= 5.3.0)

Sin ninguna definición de espacios de nombres, todas las definiciones de clases y funciones son colocadas en el espacio global - como si lo estuvieran antes de que PHP soportara los espacios de nombres. Prefijar un nombre con \ especificará que el nombre es requerido desde el espacio global incluso en el contexto del espacio de nombres.

Ejemplo #1 Usar la especificación de espacio global

<?php
namespace A\B\C;

/* Esta función es A\B\C\fopen */
function fopen() { 
     
/* ... */
     
$f = \fopen(...); // llamar a fopen global
     
return $f;

?>



add a note add a note User Contributed Notes Espacio global - [2 notes]
up
2
xmarcos at gmail dot com
11 months ago
That's the expected behavior, you have to declare the namespace at the top of the file to "extend" it.

If you include a global namespaced file, it will operate on the global namespace.
up
2
routinet
1 year ago
Included files will default to the global namespace.
<?php
//test.php
namespace test {
  include
'test1.inc';
  echo
'-',__NAMESPACE__,'-<br />';
}
?>

<?php
//test1.inc
 
echo '-',__NAMESPACE__,'-<br />';
?>

Results of test.php:

--
-test-

 
show source | credits | stats | sitemap | contact | advertising | mirror sites