- 問(wèn):此腳本執(zhí)行輸出什么,如果出現(xiàn)錯(cuò)誤如何攔截并通知管理員?
error_reporting(E_ALL);
try {
call_not_exist_method(); // 調(diào)用一個(gè)不存在的函數(shù)
} catch (Exception $e) {
}
分析:主要考察PHP錯(cuò)誤和異常處理機(jī)制,還有set_error_handler()、register_shutdown_function()、set_exception_handler()的應(yīng)用。
這里會(huì)產(chǎn)生一個(gè)Fatal error,腳本終止,try-catch不能捕獲,可以通過(guò)register_shutdown_function()函數(shù)捕獲錯(cuò)誤,https://www.cnblogs.com/zyf-zhaoyafei/p/6928149.html
請(qǐng)寫出兩個(gè)以上支持回調(diào)處理的PHP函數(shù),并自己實(shí)現(xiàn)一個(gè)支持回調(diào)的函數(shù)。
call_user_func()
call_user_func_array()
array_walk()
https://www.cnblogs.com/zhenbianshu/p/6063340.html請(qǐng)寫出兩種獲取指定文件夾下所有文件的方法(思路或代碼)
- scandir()
function getOpenFile($dir = "")
{
if(!is_dir($dir)) return false;
$file = scandir($dir);
foreach ($file as $key => $value) {
if($value != '.' && $value != '..'){
if(is_dir($dir . DIRECTORY_SEPARATOR . $value)){
getOpenFile($dir . DIRECTORY_SEPARATOR . $value);
}else{
echo $dir . DIRECTORY_SEPARATOR . $value . "<br>";
}
}
}
}
- opendir()、readdir()、closedir()
function getFile($dir = "")
{
if(!is_dir($dir)) return false;
$dh = opendir($dir);
while (($file = readdir($dh)) !== false) {
$temp = $dir . DIRECTORY_SEPARATOR . $file;
if(is_dir($temp) && $file != '.' && $file != '..'){
getFile($temp);
}else{
if($file != '.' && $file != '..'){
echo $temp."<br>";
}
}
}
closedir($dh);
}
- 寫出三種截取文件名后綴的方法或者函數(shù)。(內(nèi)置或者自定義)
字符截取、數(shù)組分割、路徑函數(shù)pathinfo
https://blog.csdn.net/zls986992484/article/details/52629684 - 寫出一段含有安全性問(wèn)題的PHP代碼,如sql注入,對(duì)于注入問(wèn)題你如何思考的?
$id = $_GET['id'];
$sql = "SELECT * FROM `notice` WHERE `id` = $id";
- 請(qǐng)寫出for while foreach三者的差異
- foreach用于循環(huán)遍歷數(shù)組
- for 用于預(yù)先知道腳本需要運(yùn)行的次數(shù)的情況
- while 條件為真一直執(zhí)行
- php如何實(shí)現(xiàn)不用自帶函數(shù)給客戶端下發(fā)cookie,對(duì)于分布式系統(tǒng)來(lái)說(shuō)如何保存session?
可以通過(guò)header設(shè)置cookie,php的setCookie也是對(duì)header的封裝
header("Set-Cookie:name=zhangsan; path=/; expires=".gmstrftime("%A,
%d-%b-%Y %H:%M:%S GMT",time()+9600));
- 如何在不修改類文件的情況下,獲取類對(duì)應(yīng)私有屬性的值?
反射