2010-04-08 102 views
1

我試圖使用PHP 5.3.2拋出一個異常,這是給我下面的錯誤:PHP 5.3.2不拋出異常

解析錯誤:語法錯誤,意想不到的T_THROW

我試圖拋出異常的方式如下:

throw new Exception('Property ' . $name . ' doesn\'t exist in class Index', ''); 

編輯:我也試着

throw new Exception('Property ' . $name . ' doesn\'t exist in class Index'); 

它ð idn't改變我得到的錯誤。

完整的方法:

public function __get($name) 
    { 
     if(property_exists($this, $name) 
      throw new Exception('Property ' . $name . ' doesn\'t exist in class Index'); 
     return $this->$name; 
    } 
+0

你可以在投擲前後顯示代碼嗎? – 2010-04-08 10:26:57

回答

4

檢查忌諱你的PHP代碼,有時我錯過掀起了 ';'這可能會導致錯誤。

也嘗試正式寫入if語句,在括號中添加。我知道它不應該有任何可能性,但誰知道編程!

+0

炮轟,你讓你經歷了方法,並意識到我離開了一個palenthesis ..謝謝。 – tipu 2010-04-08 10:29:55

+0

呵呵,沒問題,如果每發生一次我都有£1,我就會變得富有! – studioromeo 2010-04-08 10:32:58

0

你缺少你如果()線的右括號等PHP認爲這

if(property_exists($this, $name) throw new Exception(...); 

這不是有效的語法。地方),你如果()行的末尾:

if(property_exists($this, $name)) 

編輯:我討厭當我錯過一個答案下面的答覆。 :(