Re: [討論] 能不能這樣判實體化成功與否?
※ 引述《JYHuang (夏天到了,冷不起來了說)》之銘言:
: ※ 引述《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
: --
: 寫到後來,
: 有時繞一下其實不會怎麼
: 卻一直跳脫不出想要看看能不能直線通過的思維 =.=
嘛…我覺得可能沒辦法 XDD
正要出門沒時間細想,丟一個直覺上的「少一行」解
if ($file = new file ($path) && $file->success) {
// do something
}
--
我路上再想想 XD
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 175.180.182.236
→
09/27 00:25, , 1F
09/27 00:25, 1F
→
09/27 00:26, , 2F
09/27 00:26, 2F
→
09/27 00:27, , 3F
09/27 00:27, 3F
→
09/27 00:27, , 4F
09/27 00:27, 4F
→
09/27 00:28, , 5F
09/27 00:28, 5F
→
09/27 02:20, , 6F
09/27 02:20, 6F
→
09/27 02:21, , 7F
09/27 02:21, 7F
→
09/27 02:23, , 8F
09/27 02:23, 8F
→
09/27 08:27, , 9F
09/27 08:27, 9F
→
09/27 11:00, , 10F
09/27 11:00, 10F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 4 之 4 篇):