How to make PHPStorm treat a function as defined?

会有一股神秘感。 提交于 2019-12-01 21:08:28

You need what is called "stub files":

  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

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.

An example: how standard bin2hex function is defined:

<?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) {}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!