S
S
Stanislav2019-04-15 11:49:06
PHP
Stanislav, 2019-04-15 11:49:06

How to use phpDoc to describe two variants of a method at once, overloaded via __call and __callStatic?

The class has two magic methods, __call and callStatic , which overload the conditional read() method. If this method is accessed as a static method, the entity id is passed to it for reading. If it is accessed as a class instance method, nothing is passed to it, the id is taken from the instance property.
In both cases, the same either newly created or already existing instance of the class is returned. Before the class, I try to write both variants of the method like this, static and not:

/**
 * Class Entity
 *
 * @package MyCompany\Contracts
 *
 * @property array  $data
 * @property int    $id
 * @property string $name
 *
 * @method Entity read()
 * @method static Entity read( $id )
 */

But PhpStorm 2019.1 swears at such an entry like this:
Method with same name already defined in this class
Another definition with same name exists in this file

Who is right, me or PhpStorm? If I'm wrong, how can I please the latter?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2019-04-15
@lamo4ok

No, this behavior is not built into the IDE, and it cannot be prompted in any way.
If you try to declare 2 methods inside the class - with the same name, you will get exactly the same error. Method with same name already defined in this class . Actually, this is the expected behavior when you describe methods in phpDoc.

class Test {

    public function test() {
    }

    public static function test() {
    }
}

A
Anton Shamanov, 2019-04-15
@SilenceOfWinter

ide is not designed for such shitty code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question