是否可以向 PhpStorm 的用戶展示可能的函式引數是什么,而不僅僅是引數的型別?
例如,我有一個函式可以向程式員顯示需要兩個字串,如下圖所示:

然而,我想的提示,以顯示每個變數的可能值-tag并且tag_type在該示例中; 例如,
- 標記的可能值為“完整、查看、編輯、添加或洗掉”。
- 變數 tag_type 的可能值是資料庫中大約 10 個左右的活動的串列。
這是我的代碼。是否可以更改以在 PhpStorm 中向用戶顯示允許的變數值?
/**
* @param string $tag
* @param string $tag_type
* @return int
*
* [tag] = full, view, edit, add, or delete
* [type] = all, activities, grades, orders, people, schools, users, team_classes,
* coaches, team_parents, or organization
*
* by default, if leave arguments blank, you are asking if the current user is a full admin,
*/
public function isAdmin(string $tag = '', string $tag_type = ''){
if ($this->isFullAdmin())
return true;
return $this->tagas()
->where('tag', '=', 'full')
->where('tag_type', '=', $tag_type)
->orWhere(function($query) use ($tag, $tag_type) {
$query->where('tag','=',$tag)
->where('tag_type','=', $tag_type);
})->count();
}
好的,我想出了這個,但它似乎不起作用。我用 phpversion() 檢查了我的 php 版本,它是 8.0.2。
public function isAdmin(
#[ExpectedValues(['all', 'activities', 'grades', 'orders', 'people', 'schools', 'users',
'team_classes','coaches', 'team_parents', 'organization'])] string $tag_type = '',
#[ExpectedValues(['*', 'full', 'view', 'edit', 'add', 'delete'])] string $tag = '*'
){
然而,它只是稍微改變了型別暗示。

它顯示 [ExpectedValues] 但不顯示實際的預期值?
uj5u.com熱心網友回復:
您可以使用PhpStorm 高級元資料。特別是:方法功能接受的引數- 
對于 PHP 8,您可以使用#[ExpectedValues] JetBrains 制作的自定義PHP 屬性:


