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

查看:359
本文介绍了如何使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 文件并将其置于项目中(无论是项目本身..还是作为一些外部库(设置| PHP |包含路径) - 无关紧要,只要PhpStorm可以看到它在这个项目中。)

  2. 添加该功能定义,因为它将在PHP本身中完成:描述所有参数,返回类型等。只需将函数体留空。文档是可选的 - 只是你拥有的文档越多,它对PhpStorm就越有用(因为IDE可以警告你不正确的返回类型使用;无效的参数类型等)

  3. 这就是它

  1. Create a .php file and place it anywhere in your project (be it project itself .. or as some External Library (Settings | PHP | Include paths) -- does not matter, as long as PhpStorm can see it in this project).
  2. Add that function definition as it would be done in PHP itself: describe all parameters, return type etc .. just leave the body of the function empty. The documentation is optional -- just the more doc you have the more useful it will be for PhpStorm (as IDE can warn you about incorrect return type usage; invalid parameter type etc)
  3. That's it

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

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

示例:标准 bin2hex 函数定义:

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

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

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