- Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- foobar
<?php
interface A {
public function foo();
}
class B implements A {
public function foo() {
echo "foo";
}
public function bar() {
echo "bar";
}
}
class C {
public function __construct(protected A $prop) {
$this->prop->foo();
}
}
class D extends C {
public function __construct(B $prop) {// Remove "protected" so that this is just an argument, not a property
// Call the parent so that the field has a value
parent::__construct($prop);
$this->prop->bar();
}
}
$b = new B();
$d = new D($b);