報錯 Fatal error: Cannot declare function Demo2 est because the name is already in use in
問題描述
和老師一樣的代碼,報錯:
Fatal error: Cannot declare function Demo2test because the name is already in use in E:wwwrootphpbaseobjectnamespacetest2.php on line 5
test1代碼:
<?php
namespace Demo1;
function test($a,$b)
{
return $a*$b;
}
?>
test2代碼:
<?php
namespace Demo2;
require('test1.php');
use function Demo1test;
function test($a,$b)
{
return $a+$b;
}
echo test(4,5) ;// 非限定命名空間
echo "<hr>";
echo test(4,5);
?>
問題解答
回答1:你很好學,大兄弟!回答2:那就不知道了
回答3:最終結果是 9
test2.php 文件
test1.php 文件
test1.php 和 test2.php 是放在不同的 Demo1 和 Demo2 文件夾中
回答7:use function Demo1test; 這一行去掉 就可以了
回答8:老師代碼就是解決這種重名的,他演示沒有錯,我們用一樣的代碼就有錯回答9:test2 本身有一個 test方法 然后你引入的 test1 也有一個 test 方法
在同一個.php 存在相同方法 會你上邊的報錯
http://php.wyscdz.com
回答10:上面的錯誤是 php 版本是7.0.12
如果切換回 5.6.27 就報如下的錯:
Fatal error: Call to undefined function Demo1test()
相關文章:
1. css3 - css怎么實現圖片環繞的效果2. css - 定位為absolute的父元素中的子元素 如何設置在父元素的下面?3. android - 用textview顯示html時如何寫imagegetter獲取網絡圖片4. javascript - 原生canvas中如何獲取到觸摸事件的canvas內坐標?5. JavaScript事件6. html - css布局 table cellspacing7. 在mac下出現了兩個docker環境8. javascript - jquery hide()方法無效9. 注冊賬戶文字不能左右分離10. html - vue項目中用到了elementUI問題
