<?php
class B {
public $var;
public function __construct($var) {
$this->var = $var;
}
}
class A {
public $var;
public function __construct(B $var) {
$this->var = $var;
}
}
$b = new B('test');
$a = new A($b);
$b->var = 'test2';
echo $b->var;
echo $a->var;
test2
Fatal error: Uncaught Error: Object of class B could not be converted to string in /in/icqg0:21
Stack trace:
#0 {main}
thrown in /in/icqg0 on line 21
Process exited with code 255.
Output for 8.3.5
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
test2
Fatal error: Uncaught Error: Object of class B could not be converted to string in /in/icqg0:21
Stack trace:
#0 {main}
thrown in /in/icqg0 on line 21
Process exited with code 255.