<?php
class Baz {
protected $data;
function __construct($d) {
$this->data = $d;
}
function getData() {
return $this->data;
}
}
trait A {
public $a;
function run() {
echo $this->a->getData();
}
}
class Foo {
use A;
function __construct() {
$this->a = new Baz('Hello ');
}
}
class Bar {
use A;
function __construct() {
$this->a = (new Foo())->a;
}
}
(new Foo)->run();
(new Bar)->run();
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Hello Hello