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

search for in the

名前空間の使用法: グローバル関数/定数への移行> <名前空間の使用法: エイリアス/インポート
[edit] Last updated: Fri, 25 May 2012

view this page in

グローバル空間

(PHP 5 >= 5.3.0)

名前空間の定義がない場合、すべてのクラスや関数の定義はグローバル空間に配置されます。 これは、名前空間に対応する前の PHP がサポートしていた空間です。 名前の先頭に \ をつけると、 名前空間の内部からであってもグローバル空間の名前を指定することができます。

例1 グローバル空間を指定する方法

<?php
namespace A\B\C;

/* この関数は A\B\C\fopen です */
function fopen() { 
     
/* ... */
     
$f = \fopen(...); // グローバルな fopen をコールします
     
return $f;

?>



add a note add a note User Contributed Notes グローバル空間
xmarcos at gmail dot com 21-May-2012 07:08
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.
routinet 28-Aug-2011 11:22
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 | sitemap | contact | advertising | mirror sites