和老師一樣的程式碼,報錯:
Fatal error: Cannot declare function Demo2\test because the name is already in use in?E:\wwwroot\phpbase\object\namespace\test2.php?on line 5
test1程式碼:
<?php?
#namespace Demo1;
function test($a,$b)
{
? return $a*$b;
}
?>
test2程式碼:
<?php
namespace Demo2;
require('test1.php');
use function Demo1\test;
function test($a,$b)
{
? return $a $b;
}
#echo test(4,5) ;// 非限定命名空間
echo "<hr>";
echo test(4,5);
??>
##
test1.php 檔案
test1.php 和 test2.php 是放在不同的 Demo1 和 Demo2 資料夾中
use function Demo1\test;? 這一行去掉 就可以了
test2? 本身有一個test方法? 然後你引入的test1 也有一個test 方法
在同一個.php 存在相同方法會你上邊的報錯
http://php.wyscdz .com
上面的錯誤是php 版本是7.0.12
如果切換回5.6.27 就報如下的錯:
Fatal error: Call to undefined function Demo1\test()