PhpStorm 没有在 array_map 中显示代码提示

标签 php phpstorm code-completion

我没有得到这段代码的代码提示:

enter image description here

get_indexes 的 PHPDoc 我认为做得很好,NetBeans 似乎理解它并正确显示提示:

/**
 *  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 定义在同一个命名空间下的同一个文件中:

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

   /**
    * @var int
    */
   public $post_id;
...

知道问题出在哪里吗?

最佳答案

如果您知道 $recipes 总是包含 Recipe 类型的对象,那么将它用作 map 的 $recipe 参数的类型功能:

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

这样 PhpStorm(和其他 IDE)可以帮助您进行自动完成,并且当 PHP 解释器在 $recipes 中遇到错误类型的值时会触发 fatal error 。

关于PhpStorm 没有在 array_map 中显示代码提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48040747/

相关文章:

php - RESTful Zend 框架 API

php - 自动导入CSV文件并上传到数据库

php - MySQL 获取结果没有任何结果,但查询在 Mysql 工作台中工作正常

php - 在查询结束时不使用 XDEBUG_SESSION_START 开始调试

Php Storm "rsa key is corrupt or has the wrong version"

php - Codeigniter session 数据,它们只是 cookie 吗?

git - 将 bitbucket 导入 PHPStorm

javascript - 您对具有代码完成功能的简单 JavaScript 编辑器有何建议?

angularjs - Webstorm 10 代码完成不适用于 AngularJS controllerAs 语法

vim - 为什么当我按 <tab> 时 SuperTab 会输出 self?