报错 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. 怎么php怎么通过数组显示sql查询结果呢,查询结果有多条,如图。2. python - Scrapy的使用,如何请求新的URL,并回调指定的函数?3. 网页爬虫 - python requests爬虫问题4. python - 通过电影名称获取视频地址5. python - TypeError: printBB() takes 0 positional arguments but6. 请问一下关联表查询如何操作?7. javascript - 如图,百度首页,查看源代码为什么什么都没有?8. mysql - 如何在ubuntu 安裝環境?9. python - celery beat 调度如何运行期间动态添加任务?10. linux - 阿里云服务器上的mysql服务在客户端只能通过ssh证书连接后才能使用

网公网安备