<?php
class C {
private $name;
public function __construct(string $name) {
$this->name = $name;
}
public function __toString() {
return $this->name;
}
}
function f(string $a, C $b) : void {
var_dump($a, $b);
}
$a = new C('a');
$b = new C('b');
f($a, $b);
string(1) "a"
object(C)#2 (1) {
["name":"C":private]=>
string(1) "b"
}
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
string(1) "a"
object(C)#2 (1) {
["name":"C":private]=>
string(1) "b"
}
Output for 7.0.0 - 7.0.20
string(1) "a"
object(C)#2 (1) {
["name":"C":private]=>
string(1) "b"
}
Fatal error: Uncaught TypeError: Return value of f() must be an instance of void, none returned in /in/TbjSo:18
Stack trace:
#0 /in/TbjSo(23): f('a', Object(C))
#1 {main}
thrown in /in/TbjSo on line 18
Process exited with code 255.