3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait T { protected int $x; } class A { use T; } class B { use T; public function writeToA(A $a): void { $a->x = 1; } } (new B)->writeToA(new A);
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Fatal error: Uncaught Error: Cannot access protected property A::$x in /in/hM5TM:16 Stack trace: #0 /in/hM5TM(20): B->writeToA(Object(A)) #1 {main} thrown in /in/hM5TM on line 16
Process exited with code 255.

preferences:
56.33 ms | 406 KiB | 5 Q