phpStorm未检测到PHP库名称空间 [英] PhpStorm not detecting php library namespace
问题描述
我正在使用PhpStorm作为当前的IDE.
I'm using PhpStorm as current IDE.
我唯一遇到的问题是它找不到我的php库.
The only issue I have with it is that it can't find my php-library.
我已经安装了此软件: PHP-JS .
I've installed this: PHP-JS.
通过安装,我的意思是生成了一个php-js.so
文件,该文件是通过php5enmod php-js
加载的.
And by install, i mean generated the php-js.so
file which I've loaded via php5enmod php-js
.
该库的工作原理:
// This is a valid namespace AND classname
$context = new JS\Context;
$result = $context->evaluate("var x = 3; var y = 4; var z = x + y; ++z;");
// will output 8
出于某些(不是那么奇怪)的原因,PhpStorm无法找到JS
名称空间,因此找不到该名称空间中的任何类.
For some (well, not that strange) reason, PhpStorm can't find the JS
namespace and consequently no classes from that namespace.
有没有办法告诉PhpStorm我实际上是从有效名称空间的有效类中调用现有方法?
Is there a way I can tell PhpStorm that I'm actually calling an existing method from a valid class from a valid namespace?
我尝试使用docBlock标记使其工作,但似乎没有一个符合我的需求.
I've tried to make it work using docBlock tags but none seems to match what I need.
推荐答案
PhpStorm无法读取二进制.so
文件(在Windows上为.dll
)并从那里提取PHP接口(并通过"PHP接口" 我的意思是扩展在运行时提供的类/函数/常量/等.
There is no way that PhpStorm will read your binary .so
file (.dll
on Windows) and extract PHP interfaces from there (and by "PHP interface" I mean classes/functions/constants/etc that extension offers during runtime).
因此,您将需要执行与所有其他二进制php扩展一样的操作(例如
Therefore you would need to do the same as all other binary php extensions would do (e.g. Phalcon's DevTools) -- make stubs files.
存根文件是您的类/方法/函数/等的受限制的PHP版本,带有(可选)完整文档,但正文为空.您可以在任何标准PHP类(例如MySQL
)上按 Ctrl +单击并查看自己在PhpStorm中的工作方式(IDE将在另一个编辑器选项卡中打开相应的存根文件)..或仅浏览其存根.直接存储库(感谢@DanFromGermany提供链接- https://github.com/JetBrains/phpstorm-stubs ).
Stub file is a limited PHP version of your classes/methods/functions/etc with (optional) full doc but empty bodies. You can Ctrl + Click on any standard PHP class (e.g. MySQL
) and see yourself how it's done in PhpStorm (IDE will open corresponding stub file in another editor tab) .. or just browse their stub repository directly (thanks @DanFromGermany for the link -- https://github.com/JetBrains/phpstorm-stubs).
这样的存根文件的示例是(它涵盖了示例中的代码):
An example of such stub file would be (it covers the code from your example):
<?php
namespace JS;
class Context
{
/**
* Evaluate your JS code
*
* @param string $param JS code to evaluate
* @return mixed
*/
public function evaluate($param) {}
}
只需将此类存根文件放置在项目中的某个位置(或引用任何其他受支持的方式(例如,通过PHP | Include paths
进行引用)),此代码仅适用于IDE.
Just place such stub files somewhere in your project (or reference any other supported way -- e.g. via PHP | Include paths
) -- this code is for IDE only.
此类存根文件可由可以解析源.php
文件并在代码完成时从那里提供类/功能的任何IDE/编辑器使用.因此,对于该PHP-JS 请开发人员完全自动地提供此类存根(就像Phalcon开发者一样).
Such stub files can be used by any IDE/editor that can parse source .php
files and offer classes/functions from there in code completion. Therefore it makes perfect sense to ask developers of that PHP-JS to provide such stubs automatically (just like Phalcon devs do).
这篇关于phpStorm未检测到PHP库名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!