您的位置:首頁技術文章
文章詳情頁

報錯 Fatal error: Cannot declare function Demo2 est because the name is already in use in

瀏覽:111日期:2022-06-08 09:23:24

問題描述

和老師一樣的代碼,報錯:

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:

報錯 Fatal error: Cannot declare function Demo2est because the name is already in use in最終結果是 9

回答4:

報錯 Fatal error: Cannot declare function Demo2est because the name is already in use intest2.php 文件

回答5:

報錯 Fatal error: Cannot declare function Demo2est because the name is already in use intest1.php 文件

回答6:

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()

標簽: error
相關文章:
国产综合久久一区二区三区