Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在不加载源文件的情况下使用php函数?_Php_Function - Fatal编程技术网

如何在不加载源文件的情况下使用php函数?

如何在不加载源文件的情况下使用php函数?,php,function,Php,Function,我想使用我的函数,例如DebugR(),但我不想使用require或include(带有include\u path)来加载包含源代码的函数文件 我知道我可以使用自动加载,但这个操作必须在我的php配置中是通用的。我想我必须创建一个PHP扩展,但是还有其他方法吗?如果不构建扩展,或者不自动加载一类函数,或者不直接将函数加载到页面中,或者不在同一个文件中编写函数,我敢肯定没有办法不调整PHP配置 出于好奇,不想做这些事情的原因是什么?为什么不使用将代码作为BC缓存在内存中的加速器? 您仍然需要编写

我想使用我的函数,例如
DebugR()
,但我不想使用require或include(带有
include\u path
)来加载包含源代码的函数文件


我知道我可以使用自动加载,但这个操作必须在我的php配置中是通用的。我想我必须创建一个PHP扩展,但是还有其他方法吗?

如果不构建扩展,或者不自动加载一类函数,或者不直接将函数加载到页面中,或者不在同一个文件中编写函数,我敢肯定没有办法不调整PHP配置


出于好奇,不想做这些事情的原因是什么?

为什么不使用将代码作为BC缓存在内存中的加速器?
您仍然需要编写“include”指令。

如果扩展是您的目标,那么可以从任何可用的开源加速工具中选择

文件上说:

自动\u前置\u文件字符串

Specifies the name of a file that is automatically parsed before the main file. The file is included as if it was called with the require() function, so include_path is used.

The special value none disables auto-prepending.

唯一可行的方法是像这样使用自动加载:

// your_file.php
function __autoload($class)
{
    require_once('./classes/' . $class . '.php');
}

echo _::Bar();
var_dump(_::DebugR());
echo _::Foo();

// ./classes/_.php
class _
{
    function Bar()
    {
        return 'bar';
    }

    function DebugR()
    {
        return true;
    }

    function Foo()
    {
        return 'foo';
    }
}
当然,每个函数都存储在这个类中

另一种选择是,如果您在对象中工作,请使用_call()魔术方法并执行以下操作:

return $this->DebugR();

谢谢Jim Puls,我会记得如何编辑futurs问题“我知道我可以使用自动加载,但此操作必须是通用的”我不想使用自动加载。阅读投票的答案,这是对问题的最好回答。