$explode]; } } namespace{ use Notebook\Routers; exp-6ren">
gpt4 book ai didi

php - fatal error ,与 php 中的命名空间有关

转载 作者:行者123 更新时间:2023-12-04 17:03:50 24 4
gpt4 key购买 nike

我想知道为什么下面的代码会出错:

<?php 

namespace Notebook\Routers{

function exploder($request_uri){
$explode = explode("/", $request_uri);
return ["count"=> count($explode), "values"=>$explode];
}
}

namespace{
use Notebook\Routers;
exploder($_SERVER["REQUEST_URI"]);
}

它说 Fatal error: Call to undefined function exploder() in /var/www/index.php on line 13
除非我遗漏了什么。 use Notebook\Routers应该能够在当前命名空间中导入函数。

最佳答案

只需查看有关 aliasing 的文档并像这样调用你的函数:

Routers\exploder($_SERVER["REQUEST_URI"]);

关于php - fatal error ,与 php 中的命名空间有关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23001056/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com