如何使PHPStorm处理定义的函数?

Lás*_*nda 3 ide phpstorm

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

Laz*_*One 5

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

  1. 创建一个.php文件并将其放在项目的任何位置(无论是项目本身..还是作为一些外部库(设置| PHP |包含路径) - 无关紧要,只要PhpStorm可以在此项目中看到它).
  2. 添加该函数定义,因为它将在PHP本身中完成:描述所有参数,返回类型等.只是将函数体留空.文档是可选的 - 只是你拥有的文档越多,它对PhpStorm就越有用(因为IDE可以警告你不正确的返回类型使用;无效的参数类型等)
  3. 而已

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

一个例子:如何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) {}
Run Code Online (Sandbox Code Playgroud)