[英]How to tell PHP Storm that the function return static or another type
class A {
/**
* @return static|bool
*/
public static function build()
{
if (/**/) {
return new static;
}
return false;
}
}
class B extends A {}
$o = B::build();
PHP Storm無法理解$ o中是否存在B實例。 如果我在return
注釋中僅保留static
而沒有第二種類型,那么一切都正確。
目前,PhpStorm無法正確理解@return static|bool
-現在只有@return static
本身在起作用。
https://youtrack.jetbrains.com/issue/WI-23435-觀看這張票和相關票證(star / vote / comment)以獲得進度通知。
部分解決方法:通過內聯PHPDoc輸入提示該變量(在您的情況下$o
),例如
/** @var B $o */
$o = B::build();
解決方法,不是很優雅:
class A {
protected $class_name;
public static function build()
{
return $class_name::static_variable;
}
}
class B extends A {
protected $class_name="B";
}
$o = B::build();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.