3v4l.org

run code in 500+ PHP versions simultaneously
<?php trait SimpleTrait { final public function final_pub() {} public function pub() {} } class Test { use SimpleTrait { final_pub as private; pub as final; pub as private; } } foreach (['final_pub', 'pub'] as $method) { echo "--- Method: $method ---\n"; $rm = new ReflectionMethod(Test::class, $method); var_dump($rm->isFinal()); var_dump($rm->isPublic()); var_dump($rm->isPrivate()); }
Output for 8.3.0 - 8.3.1, 8.3.17 - 8.3.32, 8.4.4 - 8.4.24, 8.5.0 - 8.5.9
--- Method: final_pub --- bool(true) bool(false) bool(true) --- Method: pub --- bool(false) bool(false) bool(true)
Output for 8.3.2 - 8.3.16, 8.4.1 - 8.4.3
Warning: Private methods cannot be final as they are never overridden by other classes in /in/nJn5V on line 10 --- Method: final_pub --- bool(true) bool(false) bool(true) --- Method: pub --- bool(false) bool(false) bool(true)
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.32
Fatal error: Cannot use 'final' as method modifier in /in/nJn5V on line 12
Process exited with code 255.

preferences:
60.21 ms | 933 KiB | 4 Q