Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.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 - Fatal编程技术网

Php 如果函数不存在,如何重定向到另一个脚本?

Php 如果函数不存在,如何重定向到另一个脚本?,php,Php,我正在使用一个自定义函数,如果这个动态命名的自定义函数不存在,我想重定向到另一个脚本。 此代码段执行正确,因为函数存在: $a = '1'; call_user_func('prefix_'.$a); function prefix_1(){} 在这种情况下,找不到函数并生成错误 $a = '2'; call_user_func('prefix_'.$a); function prefix_1(){} 我需要脚本重定向到另一个页面,例如,使用header('location:error.ph

我正在使用一个自定义函数,如果这个动态命名的自定义函数不存在,我想重定向到另一个脚本。 此代码段执行正确,因为函数存在:

$a = '1';
call_user_func('prefix_'.$a);
function prefix_1(){}
在这种情况下,找不到函数并生成错误

$a = '2';
call_user_func('prefix_'.$a);
function prefix_1(){}
我需要脚本重定向到另一个页面,例如,使用
header('location:error.php')

提前谢谢。

1.使用函数检查函数是否存在

2.使用IF条件重定向error.php

3.如果功能不存在,则条件转到其他部分

if(function_exists('prefix_'.$a)){
    call_user_func('prefix_'.$a);
}else{
    header("Location: http://www.example.com/error.php");
}

1.使用函数\u exists检查函数是否存在

2.使用IF条件重定向error.php

3.如果功能不存在,则条件转到其他部分

if(function_exists('prefix_'.$a)){
    call_user_func('prefix_'.$a);
}else{
    header("Location: http://www.example.com/error.php");
}

?我已尝试使用此功能,但无法。为什么不能?它可以在我的本地开发设备上运行…您能告诉我们您是如何使用函数_exists()的吗?
函数_exists()
只需要函数名作为字符串。。。所以
如果(!function_存在('prefix_u'.$a)){…}
?我已经尝试过使用这个功能,但是我不能。为什么不呢?它可以在我的本地开发设备上运行…您能告诉我们您是如何使用函数_exists()的吗?
函数_exists()
只需要函数名作为字符串。。。所以
如果(!function_存在('prefix_u'.$a)){…}