Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
614 views
in Technique[技术] by (71.8m points)

ide - How to make PHPStorm treat a function as defined?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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) {}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...