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.4.4 - 8.4.28, 8.5.0 - 8.5.13, 8.6.0, 8.3.17 - 8.3.37, 8.3.0 - 8.3.1
--- Method: final_pub --- bool(true) bool(false) bool(true) --- Method: pub --- bool(false) bool(false) bool(true)
Output for 8.4.1 - 8.4.3, 8.3.2 - 8.3.16
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.36
Fatal error: Cannot use 'final' as method modifier in /in/nJn5V on line 12
Process exited with code 255.

preferences:
14.37 ms | 1179 KiB | 6 Q