mardi 4 décembre 2018

Type-casting problem while building fluid interface

For example we have the following abstract class

<?php
    class AbstractClass {
        public function setParam(): AbstractClass {}
    }

    class ConcreteClass extends AbstractClass {
        public function test():void {}
    }

When you'll try to use it like this

<?php
(new ConcreteClass())->setParam()->test();

Then after setParam we will see only setParam method, because setParam returns AbstractClass. I tried to mark setParam inside AbsractClass with PHP-doc @return self, but it doesn't work.

Is there solve of this problem?

Aucun commentaire:

Enregistrer un commentaire