【问题标题】:PhpStorm: Only Link to Function in included CodePhpStorm:仅链接到包含代码中的函数
【发布时间】:2017-01-31 19:53:49
【问题描述】:

在我的 PhpStorm 项目中,我有以下 3 个文件:

sub.php:

<?php
    function do_something() {
        // do something
    }
?>

sub_debug.php:

<?php
    function do_something() {
        // do something with debugging
    }
?>

main.php:

<?php
    include 'sub.php';

    do_something();
?>

所以在我的 main.php 中,我通常会包含sub.php,只有在需要调试时才切换到sub_debug.php。所以在任何时候,我只包含这两个 PHP 文件之一,并且只有一个 do_something() 函数在范围内。

但是,当我在 PhpStorm 中按住 CTRL 键单击 main.php 中的 do_something() 调用时,它仍然通知我有多个实现并提示我选择一个。

是否可以将 PhpStorm 配置为仅链接到 include-d 代码而不是项目中的所有 PHP 文件?

【问题讨论】:

    标签: php phpstorm


    【解决方案1】:

    PhpStorm 在处理定义时不考虑include/require 语句——它假设(出于方便和性能原因)所有全局实体(如函数/类等)总是可访问的(例如类可以被自动加载..或其他地方包含/需要具有功能的必要文件)。


    考虑一下这种情况:在您的main.php 中包含另一个文件(例如include 'another.php';),在该another.php 文件中您调用do_something();

    考虑到 another.php 没有任何 include/require 语句 - IDE 应该如何确定哪个 do_something(); 到这里?

    使用当前方法,它在两种情况下都提供相同的用户体验。


    无论如何:https://youtrack.jetbrains.com/issue/WI-4095 似乎与您的请求有关。

    考虑观看此票证和相关票证 (str/vote/comment) 以获取有关任何进展的通知。

    【讨论】:

      猜你喜欢
      • 2013-08-15
      • 1970-01-01
      • 2011-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多