On 26/08/2021 14:47, Olle Härstedt wrote:
Don't know if this already exists, but maybe we could consider
brainstorming or gather alternatives for different types of
encapsulation when using composition?
Although not quite equivalent to your suggestions, these threads on
making delegation to an encapsulated object might be interesting to you:
* https://externals.io/message/103353
* https://github.com/php/php-src/pull/5168
If we had something like that, then perhaps there could be a
"delegatable" visibility, which was the equivalent for "protected", but
when delegating rather than inheriting, e.g.
class Foo {
private int $a = 1;
delegatable int $b = 2;
}
class Bar {
private delegate Foo $foo;
public function __construct(Foo $foo) {
$this->foo = $foo;
echo $this->a; // Error: can't access private property of a
different class
echo $this->b; // allowed: access is to a "delegatable"
property, in a "delegated" context
}
}
--
Rowan Tommins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php