Class Composition Hinting

Is there any way to get property/method hinting when using composition? Hinting has worked great so far but when I tried to test some code I noticed that it didn't give me any hinting from composition. The object has a lot of methods/properties so hinting would be really useful. Is there any option or way to get it to give me some hinting when using composition?

new main();
class main{

    protected $buffer;


    public function __construct(){
        $this->startup();
        $this->main();
    }

    protected function startup(){
        $this->buffer = new pri\buffer();
    }

     public function main(){



        $this->buffer->????
}

???? = one of the many methods/properties in my object

0
3 comments

Hi there,

PHPDoc?

/** @var MyBufferClass */

protected $buffer;


P.S.
@var is considered deprecated (as of PhpDocumentor v2) -- you can use @type instead (although @var still will be supported for a loooong time -- for compatibility reasons).

https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md#824-var-deprecated

1
Avatar
Permanently deleted user

Found out what the problem was. If I put the "new object" in the constructor then PHPStorm reads it but if it is a method in the constructor it doesn't read it.

Works:

public function __construct(){
        $this->buffer = new core\buffer();
        $this->startup();
        $this->main();
    }


Doesn't Work:

public function __construct(){
        $this->startup();
    }

    protected function startup(){
        $this->buffer = new pri\buffer();
    }
0

Property assignments in constructors have some extra special treatment compared to the same in other methods.

PHPDoc comments solves such "problems" regardless of where property assigment is located.

1

Please sign in to leave a comment.