Welcome Guest, Not a member yet? Register   Sign In
VS Code typenit parent class (interface)
#1

PHP Code:
class {
}

class 
extends {
}

interface 
AI {
    public function test(A $a);
}

class 
Run implements AI {
    public function test(B $b// Method 'App\Services\Run::test()' is not compatible with method 'App\Services\AI::test()'.intelephense(1038)
    {
        return;
    }

Can you help with that? In fact, this is acceptable, since class B is extensible to A
Simple CI 4 project for beginners codeigniter-expenses
Reply
#2

No, it is not acceptable. B is not A.
See https://3v4l.org/nHa6i

But the opposite is acceptable.
See https://3v4l.org/c1sQb
Reply
#3

PHP Code:
class {
}

class 
extends {
}

interface 
AI {
    public function test(A $a);
}

class 
Run implements AI {
    /**
    * @param B $a
    */
    public function test(A $a)
    {
        return __METHOD__;
    }
}


$b = new B();
$run = (new Run())->test($b); 
Sorry, I didn't wake up. Yes, we can't change the interface definition. It is necessary to clarify in PHPDoc. I hurried
Simple CI 4 project for beginners codeigniter-expenses
Reply




Theme © iAndrew 2016 - Forum software by © MyBB