3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A {} class B {} class C { public function __construct( protected A|B $b ) { if ($this->b instanceof A) { trigger_error('A is deprecated, pass B instead', E_USER_DEPRECATED); $this->b = new B(); } var_dump($this->b); } } new C(new A()); new C(new B());
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
Deprecated: A is deprecated, pass B instead in /in/CLnhZ on line 11 object(B)#3 (0) { } object(B)#3 (0) { }

preferences:
55.18 ms | 406 KiB | 5 Q