2015-02-11 77 views
0

我有一個奇怪的問題與xdebugger。你能想出一個合乎邏輯的解釋嗎?oO?xDebug調用nonExisting屬性

我有一個類:

abstract class AbstractEntity 
{ 

    public $last_modified; 
    public $massEntry = array(); 

    public function __construct(array $properties = null) 
    { 
     if (!empty($properties)) { 
      $this->assignProperties($properties); 
     } 
    } 

    public function __set($property, $value = null) 
    { 
     if (property_exists($this, $property)) { 
      $this->$property = $value; 
      return $this; 
     } 
     throw new InvalidPropertyException("Property $property not found."); 
    } 

    public function __get($property) 
    { 
     if (property_exists($this, $property)) { 
      return $this->$property; 
     } 
     throw new InvalidPropertyException("Property $property not found."); 
    } 
    public function assignProperties(array $properties) 
    { 
     $availableProps = array_keys(get_object_vars($this)); 

     foreach ($availableProps as $property) { 
      if (isset($properties[$property])) { 
       $this->$property = $properties[$property]; 
      } 
     } 
    } 

    public function toArray() 
    { 
     return (array) $this; 
    }..... 

這用作數據庫對象的基。當我使用一個對象通過一個DB適配器像來填充它:

$entity = new EntityExtendingTheClass($arrayOfData); 

現在,這裏是怪異的一部分,當我正常運行腳本我沒有得到任何錯誤。但是當我運行它與斷點我得到這個奇怪的問題:

Property composites not found 

奇怪的是。我沒有在整個項目中擁有這個屬性。所以它沒有辦法從代碼中獲取它。

最bizzare的事情是當我緩存錯誤,我得到的電話,一個不存在的屬性被嘗試被稱爲。我的coude沒有。

任何消耗?

UPDATE:

只是試圖讓它停下通過斷點(出desparation)和無斷點。

最大的問題在於它只發生在我嘗試在調試器中創建對象時發生。如果我滑雪它不會破壞.... WTH?

回答

1

Xdebug在調試時分配屬性。你可以添加一些東西來檢查組合屬性?

public function __get($property) 
{ 
    if (property_exists($this, $property) || $property == 'composites') { 
     return $this->$property; 
    } 
    throw new InvalidPropertyException("Property $property not found."); 
} 

只是拋出它作爲一個建議 - 可能工作? :)也許你也可以檢查是否安裝了xdebug,並且只在這種情況下檢查組合結構?

HTH