Neo's Blog

首頁 相本 討論 書籤

分類目錄
本站日誌 (51)
碎碎唸啦 (173)
網站架設 (84)
程式設計 (161)
軟體使用 (69)
電子商務 (126)
經營奇想 (48)
基金理財 (11)
聰明消費 (87)
電影心得 (47)
開放原碼 (16)
工作記錄 (2)
毛毛小記 (9)
就是不同 (2)




歷史資料
 




July 01, 2007
[PHP] __get 在物件內部使用要注意..

PHP5 的 __get 在物件內找不到 method 或 member 時便會執行,如果我們直接在內部使用會怎樣?

<?php
$t = new Test();

class Test {

 public function __construct() {
 echo $this->x."<br>";
 echo 'isset:'.isset($this->x)."<br>";
 echo 'empty:'.empty($this->x)."<br>";
 }

 private function __get($var){
  return $var;
 }
}
?>

執行結果:

x
isset:
empty:1

雖然 $this->x 會回傳 __get 執行的結果,但是 $this->x 並不是實際存在的 member variable,所以在內部使用的時候不能因為 $this->x 會回傳資料而使用 empty (註) 來判別回傳的資料是否為空。

註:
empty - Determine whether a "variable" is empty
isset - Determine whether a "variable" is set

 
由 Neo 發表於 July 1, 2007 04:14 AM 收進你的MyShare個人書籤  

發表迴響  
(*星號開頭為必填欄位)











(請輸入您看到的數字,看不到請按右鍵->顯示圖片)


記住我的資訊?







Copyright 2005 Neo's Blog All rights reserved.