0
我正在嘗試使用PHPStorm在PHP中編寫一些抽象的MVC類。我用於泛型類包裝器的一些重寫類屬性往往更適合使用靜態方法和屬性。 代碼工作正常,但每當我用一個變量來表示一個類名稱時,將它指向一個靜態變量(存在於繼承方法中的一個變量)時,PHPStorm不知道如何處理它並在IDE中將其顯示爲錯誤。我只是想知道是否有更好的方法來做這種事情,或者如果它只是我必須學會在IDE中忽略的東西。使用變量來表示PHPStorm中的靜態屬性的類名稱
例子:
class AbstractModel {
protected static $_dataMapper = null;
protected static $_subs = null;
public function __construct($data=null) {
// constructor omitted with things like a generic class init, etc.
}
// $_subs is a static array who's value is a class name use for
// populating sub-objects as part of a class instance
public function setSubProperty($subKeyName,$value) {
$dataType = get_called_class();
/*************************************
* PHPStorm complains here on $_subs *
*************************************/
if(is_array($dataType::$_subs)
&& array_key_exists($subKeyName,$dataType::$_subs)) {
$setMethod = 'set' . ucfirst($subKeyName);
return $dataType->$setMethod($value);
} else {
return false; // or throw an exception
}
}
}
class SomedataModel extends AbstractModel {
public $other = null;
protected static $_subs = array(
'other' => "OtherModel"
);
public function __construct($data=null) {
parent::__construct($data=null);
foreach(array_keys(self::$_subs) as $_k) {
$setMethod = 'set'.ucfirst($_k);
$this->$setMethod();
}
}
public function setOther($data=null) {
// sanitize and set instance of 'other' as $this->other
}
}