Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用fluent界面的代码完成功能?_Php_Eclipse_Ide_Phpdoc - Fatal编程技术网

Php 如何使用fluent界面的代码完成功能?

Php 如何使用fluent界面的代码完成功能?,php,eclipse,ide,phpdoc,Php,Eclipse,Ide,Phpdoc,我想知道如何对继承的类使用自动完成。例如,我有这样的代码: <?php class A { /** * @return $this */ function a(){ return $this; } /** * @return $this */ function b(){ retur

我想知道如何对继承的类使用自动完成。例如,我有这样的代码:

<?php
    class A {

        /**
         * @return $this
         */
        function a(){
            return $this;
        }

        /**
         * @return $this
         */
        function b(){
            return $this;
        }
    }

    class B extends A{
        function c() {
        }
    }

    $object = new b();
    $object->a()->b()->c();
    ?>

当我尝试使用ctrl+单击导航时,我可以找到a和b函数,但如何才能找到c


谢谢。

您必须使用Eclipse的正确样式文档来添加自动完成。在@return语句中,必须指明返回的实际类型(类的名称),而不是变量:

<?php
    class A {

        /**
         * @return A
         */
        function a(){
            return $this;
        }

        /**
         * @return A
         */
        function b(){
            return $this;
        }
    }

    class B extends A{
        /**
         * @return B
         */
        function c() {
        }
    }

    $object = new B();
    $object->a()->b()->c();
?>


现在,在您的示例中,问题是它不能真正与子类一起工作,因为文档中说,例如for$object->a()返回类a的实例。因此,autocomplete不会显示类B中的方法(尽管您可以调用它们).

您必须使用Eclipse的正确样式文档来添加自动完成。在@return语句中,必须指明返回的实际类型(类的名称),而不是变量:

<?php
    class A {

        /**
         * @return A
         */
        function a(){
            return $this;
        }

        /**
         * @return A
         */
        function b(){
            return $this;
        }
    }

    class B extends A{
        /**
         * @return B
         */
        function c() {
        }
    }

    $object = new B();
    $object->a()->b()->c();
?>


现在,在您的示例中,问题是它不能真正与子类一起工作,因为文档中说,例如for$object->a()返回类a的实例。因此,autocomplete不会显示类B中的方法(您可以调用它们)。

您的意思是称为
fluent interface
,非
自动完成
。您可能需要编辑您的问题。:)仅供参考,它不适用于PHP Storm。您的意思是称为
fluent interface
,而不是
autocompletion
。您可能需要编辑您的问题。:)仅供参考,它不适用于PHP Storm。你是对的,我在代码中使用了这种语法,但它对子类的效果并不好。PHP仍然是一种动态语言,所以你只能自动完成那么多。你可以在你的超类中编写@returna | B,或者在你的子类中将它们作为神奇的方法记录下来(还没有测试它是否有效:),我将深入研究phpdoc文档。谢谢。你说得对,我在代码中使用了这种语法,但对于子类来说效果并不好。PHP仍然是一种动态语言,所以你只能自动完成那么多。你可以在你的超类中编写@returna | B,或者在你的子类中将它们作为神奇的方法记录下来(还没有测试它是否有效:),我将深入研究phpdoc文档。谢谢