php / phpDoc - @return instance of $this class?

前端 未结 5 1481
温柔的废话
温柔的废话 2021-02-07 16:08

How do I mark a method as \"returns an instance of the current class\" in my phpDoc?

In the following example my IDE (Netbeans) will see that setSomething always returns

5条回答
  •  南旧
    南旧 (楼主)
    2021-02-07 16:18

    !SOLVED! - upgrade to netbeans 9.0 (stable as of July 2018?)

    I have been after this for over a year and finally have an open source solution! :)

    class Input extends BasicHtml
    {    
        public function someOnlyInputFunc()
        {
    
        }
    }
    
    class Table extends BasicHtml
    {
        public function tableOnlyFunc()
        {
    
        }
    }
    
    abstract class BasicHtml
    {
    
        /**
         * 
         * @param array $arrayForNow
         * @return $this
         */
        public function setStyle( array $arrayForNow )
        {        
            return $this;
        }
    }
    
    
    /////driver
    $table = new Table();
    $input = new Input();
    $input->setStyle(array())->//now shows only Input + baseHtml functions
    $table->setStyle(array())-> //now shows only Table + baseHtml functions
    ///note - in 8.0.2 version it shows blank obj drop downs on exact same code.
    

    This also works with traits. As of 11/1/2018 9.0 comes as a big zip (no clean installer for windows, mac?) and you will have to search for adding the php plugings etc BUT IT DOES WORK! Took me about an hour to get it all set. I also have my old 8.x installed and running along side the new 9.0 without issue...so far (just don't run them both at same time). Plugin tip: https://www.reddit.com/r/PHP/comments/9gtaaw/how_to_run_netbeans_9_with_php_support/

提交回复
热议问题