【问题标题】:"Call to undefined function" using "use function" in php 5.6.2在 php 5.6.2 中使用“使用函数”“调用未定义函数”
【发布时间】:2016-03-10 16:03:51
【问题描述】:

我不知道我是不是在问一个愚蠢的问题。但是在 php 5.6.2 中使用命名空间函数时出现以下问题。
我正在关注此手册页:
http://php.net/manual/en/language.namespaces.importing.php

在示例中它说:

// aliasing a function (PHP 5.6+)
use function My\Full\functionName as func;
//some other examples in between;
func(); // calls function My\Full\functionName

所以我尝试了这个:
文件1.php

<?php
namespace A;
function func() {
    return "Hohoho!";
}
?>

index.php

use function A\func as hohoho;
echo hohoho();

PHP 给我以下错误:

Fatal error: Call to undefined function A\func()

我很困惑。

【问题讨论】:

  • 您是否将file1.php 包含在index.php 中?

标签: php namespaces autoload


【解决方案1】:

index.php 中包含file1.php

include 'file1.php';

【讨论】:

    猜你喜欢
    • 2014-06-15
    • 1970-01-01
    • 2019-06-01
    • 1970-01-01
    • 2013-08-22
    • 2018-07-21
    • 2015-09-21
    • 2017-07-20
    • 2015-11-18
    相关资源
    最近更新 更多