<?php
class Foo {
public function __construct(private Bar $bar, private string $_value = 'foo') {}
public string $value {
get => $this->_value;
set {
$this->bar->doSomething($this);
$this->_value = $value;
}
}
}
class Bar {
public function doSomething(Foo $foo): void {
$oldValue = $foo->value;
}
}
$foo = new Foo(new Bar());
$foo->value = 'bar';