Gez*_*zim 1 php code-completion phpstorm
我没有获得此代码的代码提示:
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;
}
Run Code Online (Sandbox Code Playgroud)
Recipe 在同一名称空间下的同一文件中定义:
class Recipe {
/**
* @var int
*/
public $recipe_id;
/**
* @var int
*/
public $post_id;
...
Run Code Online (Sandbox Code Playgroud)
任何想法可能是什么问题?
如果您知道$recipes始终包含类型的对象,Recipe则将其用作$recipemap函数的参数类型:
$post_ids = array_map(function(Recipe $recipe) {
return $recipe->recipe_id;
}, $recipes);
Run Code Online (Sandbox Code Playgroud)
这样,PhpStorm(和其他IDE)可以帮助您完成自动完成,并且PHP解释器在遇到$recipes错误类型的值时会触发致命错误.