Re: [討論] 能不能這樣判實體化成功與否?
※ 引述《gpmm (銀色)》之銘言:
: 其實看你的例子還是不很明白你要做什麼 o_Oa"
: 另外如果會有「實體化失敗」的情況那應該是直接噴 error 了吧?
class file{
public $file_path;
public $file_name;
public $success=false;
public functoin __construct($full_name){
if (file_exists($full_name) && is_file($full_name))
$this->success = true;
$this->file_name = basename($full_name);
$this->file_path = dirname($full_name;
}
}
因為我是要視內部條件來決定是否能實體化
看看能不能把下列
$file = new file(file_with_path);
if($file->success){
//dome something
}
簡化變成
if($file = new file(file_with_path){
//dome something
}
這麼懶而以 XDD
--
寫到後來,
有時繞一下其實不會怎麼
卻一直跳脫不出想要看看能不能直線通過的思維 =.=
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 112.104.145.107
→
09/26 17:25, , 1F
09/26 17:25, 1F
→
09/26 17:26, , 2F
09/26 17:26, 2F
推
09/26 18:50, , 3F
09/26 18:50, 3F
推
09/26 21:16, , 4F
09/26 21:16, 4F
→
09/26 22:43, , 5F
09/26 22:43, 5F
→
09/26 22:44, , 6F
09/26 22:44, 6F
→
09/27 00:25, , 7F
09/27 00:25, 7F
討論串 (同標題文章)