我正在使用自定義函數,如果此動態命名自定義函數不存在,我想重定向到另一個腳本。此代碼段正確執行,因為該函數存在:$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 回答

慕桂英4014372
TA貢獻1871條經驗 獲得超13個贊
1.使用function_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");
}
- 1 回答
- 0 關注
- 117 瀏覽
添加回答
舉報
0/150
提交
取消