日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

细说php这么难懂,挺难懂的解决方法

發布時間:2023/12/19 php 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 细说php这么难懂,挺难懂的解决方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

挺難懂的

下面這段代碼如何理解呢,最好在關節點上給與解釋

*?行為模型實例

*

*?@param?string?$model?模型名稱

*?@return?obj?對象形式的返回結果

*/

function?Logic($model?=?null,?$base_path?=?null){

static?$_cache?=?array();

$cache_key?=?$model.'.'.$base_path;

if?(!is_null($model)?&&?isset($_cache[$cache_key]))?return?$_cache[$cache_key];

$base_path?=?$base_path?==?null???BASE_DATA_PATH?:?$base_path;

$file_name?=?$base_path.'/logic/'.$model.'.logic.php';

$class_name?=?$model.'Logic';

if?(!file_exists($file_name)){

return?$_cache[$cache_key]?=??new?Model($model);

}else{

require_once($file_name);

if?(!class_exists($class_name)){

$error?=?'Logic?Error:??Class?'.$class_name.'?is?not?exists!';

throw_exception($error);

}else{

return?$_cache[$cache_key]?=?new?$class_name();

}

}

}

------解決思路----------------------

function?Logic($model?=?null,?$base_path?=?null){

//定義靜態變量

static?$_cache?=?array();

//定義緩存key值

$cache_key?=?$model.'.'.$base_path;

//若是靜態變量中有這個模型的實例就直接返回

if?(!is_null($model)?&&?isset($_cache[$cache_key]))?return?$_cache[$cache_key];

//組織類文件路徑

$base_path?=?$base_path?==?null???BASE_DATA_PATH?:?$base_path;

$file_name?=?$base_path.'/logic/'.$model.'.logic.php';

$class_name?=?$model.'Logic';

//類文件是否存在

if?(!file_exists($file_name)){

//不存在就實例一個model

return?$_cache[$cache_key]?=??new?Model($model);

}else{

//存在就引入

require_once($file_name);

//判斷是否存在?該類

if?(!class_exists($class_name)){

//不存在就拋出異常

$error?=?'Logic?Error:??Class?'.$class_name.'?is?not?exists!';

throw_exception($error);

}else{

//存在就實例化它,存入靜態數組中并返回

return?$_cache[$cache_key]?=?new?$class_name();

}

}

}

總結

以上是生活随笔為你收集整理的细说php这么难懂,挺难懂的解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。