2017-12-31 23 views
2

array_mapを内部のヒントません:PhpStormコードを示すことは、私はこのコードにはコードヒントを得ない

enter image description here

たPHPDoc get_indexesのためだと思うが適切に行われ、NetBeansはそれを正しく理解しているようだとショーのヒント:

class Recipe { 
    /** 
    * @var int 
    */ 
    public $recipe_id; 

    /** 
    * @var int 
    */ 
    public $post_id; 
... 
/** 
* Get Index 
* 
* @global object $wpdb 
* @param String $extension_table_name 
* @return \ZRDN\Recipe[] 
*/ 
public static function get_indexes($extension_table_name) { 
    global $wpdb; 
    $db_name = $wpdb->prefix . $extension_table_name; 
    $selectStatement = "SELECT * FROM `{$db_name}`"; 
    $recipe_indexes = $wpdb->get_results($selectStatement); 

    return $recipe_indexes; 
} 

Recipeは、同じ名前空間の下に同じファイルで定義されています

何が問題なのでしょうか?

+5

PhpStormはこのような使用例をまだカバーしていないようです。 '$ recipe'をインラインPHPDocで手動​​でヒントしてください。 – LazyOne

+0

参考のために:JetBrains Forums:https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000790250-Code-hinting-not-working-と同じです。要するに、手動でタイプヒント(PHPDocまたはPHPのネイティブタイプヒント)。 PhpStorm機能チケット - https://youtrack.jetbrains.com/issue/WI-18347 – LazyOne

+0

NetBeansがこれをどのようにサポートしていますが、PhpStormをサポートしていないのは意味がありません。私は切り替えを考えましたが、私はPhpStormでデバッグをしていますが、問題を解決したくありません。 – Gezim

答えて

5

あなたは$recipesは、常にタイプRecipeのオブジェクトが含まれていることがわかっている場合は、マップ機能の$recipe引数の型としてそれを使用する:

$post_ids = array_map(function(Recipe $recipe) { 
    return $recipe->recipe_id; 
}, $recipes); 

PhpStorm(および他のIDEが)のお手伝いをすることができます。この道をまた、間違った型の$recipesの値を検出すると、PHPインタプリタは致命的なエラーを引き起こします。

関連する問題