如何使 PHPStorm 按定义处理函数? [英] How to make PHPStorm treat a function as defined?

查看:11
本文介绍了如何使 PHPStorm 按定义处理函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

double_metaphone() 函数在 PECL 扩展中定义,因此 PHPStorm 无法看到它被定义.我不希望看到任何关于此的警告.我假设我可以让 PHPStorm 将此函数调用视为通过某种注释定义的,但我不知道如何实现.

The double_metaphone() function is defined in a PECL extension and as such PHPStorm cannot see it being defined. I wouldn't like to see any warnings about this. I assume I could make PHPStorm treat this function call as defined through some kind of annotation but I don't know how to make this happen.

推荐答案

你需要所谓的存根文件":

You need what is called "stub files":

  1. 创建一个 .php 文件并将其放在您的项目中任何地方(无论是项目本身......还是作为外部库(Settings| PHP | 包含路径) -- 没关系,只要PhpStorm在本项目中能看到就行了).

  1. Create a .php file and place it anywhere in your project (be it project itself... or as an External Library (Settings | PHP | Include paths) -- it does not matter, as long as PhpStorm can see it in this project).

像在 PHP 中那样添加函数定义:描述所有参数、返回类型等,然后将函数体留空.

Add that function definition as it would be done in PHP itself: describe all parameters, return type etc. and just leave the body of the function empty.

文档是可选的:文档越多,对 PhpStorm 和您就越有用:IDE 可以警告您参数类型无效、返回类型使用不正确、使用代码完成时建议适当类型的变量对于该功能等.

The documentation is optional: it's just the more doc you have the more useful it will be for PhpStorm and you: the IDE can warn you about invalid parameter type, incorrect return type usage, suggest variables of appropriate types when using code completion for that function etc.

就是这样

这正是所有已知的 PHP 函数/类/等首先在 PhpStorm 中完成的方式:只需在任何标准函数/类/常量上 Ctrl + 单击 并自己查看.

That's exactly how ALL known PHP functions/classes/etc are done in PhpStorm in the first place: just Ctrl + Click on any standard function/class/constant and see it yourself.

一个例子:标准bin2hex函数是如何定义的(早在2013年):

An example: how standard bin2hex function is defined (back in 2013):

<?php
/**
 * (PHP 4, PHP 5)<br/>
 * Convert binary data into hexadecimal representation
 * @link http://php.net/manual/en/function.bin2hex.php
 *
 * @param string $str A character.
 * @return string the hexadecimal representation of the given string.
 */
function bin2hex ($str) {}

您可以在这个官方 repo 中查看所有当前的 PhpStorm 存根(以及 IDE 用于完成 PHP 的其他帮助文件):https://github.com/JetBrains/phpstorm-stubs

You can see all current PhpStorm stubs (and other helper files that IDE uses for PHP completion) in this official repo: https://github.com/JetBrains/phpstorm-stubs

这篇关于如何使 PHPStorm 按定义处理函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆