You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php namespace Jack { $varA=__NAMESPACE__;
const constA="这个一个常量";
function fnA(){ echo __NAMESPACE__."中的函数".__FUNCTION__.PHP_EOL; }
class ClassA{ public $varA=2;
public function fnA(){ echo __NAMESPACE__.__FUNCTION__.PHP_EOL; } }
echo $varA.PHP_EOL;
fnA();
$obj=new ClassA; $obj->fnA(); }
namespace Tom { $varA=__NAMESPACE__;
const content="这个一个常量";
function fnA(){ echo __NAMESPACE__.__FUNCTION__.PHP_EOL; }
class ClassA{ public $varA=2;
public function fnA(){ echo __NAMESPACE__.__FUNCTION__.PHP_EOL; } }
echo $varA.PHP_EOL;
fnA();
$obj=new ClassA; $obj->fnA(); }
//全局代码 namespace{ $varA="全局代码中的变量"; echo $varA.PHP_EOL;
//调用其中一个命名 // echo Jack\$varA.PHP_EOL; //变量不在命名空间的作用范围内 echo Jack\constA; //常量 Jack\fnA(); //函数 $objA=new Jack\ClassA; //类 echo $objA->varA.PHP_EOL;
//echo Tom\$varA.PHP_EOL; }
?>
|