我不知道我是不是在问一个愚蠢的问题。 但是我在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所以我尝试了这个: file1.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()我很困扰。 有人可以帮我吗? 提前致谢。
I don't know if I'm asking a stupid question. But I have the following problem when using namespaced function in php 5.6.2. I'm following this manual page: http://php.net/manual/en/language.namespaces.importing.php
In the example it says:
// aliasing a function (PHP 5.6+) use function My\Full\functionName as func; //some other examples in between; func(); // calls function My\Full\functionNameSo I tried this: file1.php
<?php namespace A; function func() { return "Hohoho!"; } ?>index.php
use function A\func as hohoho; echo hohoho();PHP gives me the following error:
Fatal error: Call to undefined function A\func()I am very confused.
最满意答案
在index.php包含file1.php 。
include 'file1.php';Include file1.php inside index.php.
include 'file1.php';使用php 5.6.2中的“use function”调用“未定义的函数”(“Call to undefined function” using “use function” in php 5.6.2)我不知道我是不是在问一个愚蠢的问题。 但是我在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所以我尝试了这个: file1.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()我很困扰。 有人可以帮我吗? 提前致谢。
I don't know if I'm asking a stupid question. But I have the following problem when using namespaced function in php 5.6.2. I'm following this manual page: http://php.net/manual/en/language.namespaces.importing.php
In the example it says:
// aliasing a function (PHP 5.6+) use function My\Full\functionName as func; //some other examples in between; func(); // calls function My\Full\functionNameSo I tried this: file1.php
<?php namespace A; function func() { return "Hohoho!"; } ?>index.php
use function A\func as hohoho; echo hohoho();PHP gives me the following error:
Fatal error: Call to undefined function A\func()I am very confused.
最满意答案
在index.php包含file1.php 。
include 'file1.php';Include file1.php inside index.php.
include 'file1.php';
发布评论