xxxxxxxxxx
declare(strict_types=1);
abstract class AbstractValue
{
public function __get(string $name): mixed
{
return 123;
}
public function __set(string $name, mixed $value): void
{
}
}
/** @property int $foo */
final class FooValue extends AbstractValue
{
}
/** @template T of AbstractValue */
abstract class AbstractClass
{
/** @var T */
private AbstractValue $value;
/** @param T $value */
public function __construct(AbstractValue $value)
{
$this->value = $value;
}
/** @return T */
protected function getValue(): AbstractValue
{
return $this->value;
}
}
/** @extends AbstractClass<FooValue> */
final class Test extends AbstractClass
{
public function __construct()
{
parent::__construct(new FooValue());
// Works:
echo $this->getValue()->foo;
// Works:
$v = $this->getValue();
$v->foo = 1;
// Fails with: Magic instance property FooValue::$foo is not defined
$this->getValue()->foo = 1;
}
}