dismiss Step into the future! Click here to switch to the beta php.net site
downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

__NAMESPACE__> <Usando namespaces
[edit] Last updated: Fri, 28 Jun 2013

view this page in

Espaço global

Sem definição de namespace, todas as definições de classes e funções são colocadas no espaço global - como era feito no PHP antes dos namespaces serem suportado. Prefixando o nome com \ especificará que o nome é requerido do espaço global até mesmo no contexto do namespace.

Exemplo #1 Usando a especificação de espaço global

<?php
    
namespace A\B\C;
 
 
/* This function is A\B\C\fopen */
    
function fopen() { 
         
/* ... */
         
$f = \fopen(...); // call global fopen
         
return $f;
    } 
?>



add a note add a note User Contributed Notes Espaço global - [2 notes]
up
2
xmarcos at gmail dot com
1 year 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