0
<?php

interface iFoo {
    public function print(): iFoo;
}

class Foo implements iFoo {
    public function print(): iFoo {
        return $this;
    }

    public function chain(): iFoo {
        return $this;
    }
}

$foo = new Foo();
$foo->print()
    ->chain() // Method 'chain' not found in iFoo
    ->print();

How can I make PhpStorm recognize the chain method, even though it's not in the contract?

2 Answers 2

1

It's because you're telling PHPStorm that you're going to have a return type of iFoo which doesn't have the class chain() if your return type is Foo I would guess this would work.

Sign up to request clarification or add additional context in comments.

1 Comment

It wouldn't because it doesn't match the contract, also I can't set Foo as return type in the interface.
1

print() method returns iFoo instance:

public function print(): iFoo {

iFoo does not contain chain() method, that's why you see "method not found". You can change the return type to Foo or add chain() method to iFoo.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.