3v4l.org

run code in 300+ 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.25, 8.4.4 - 8.4.12
--- 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.33, 8.2.0 - 8.2.29
Fatal error: Cannot use 'final' as method modifier in /in/nJn5V on line 12
Process exited with code 255.

preferences:
58.11 ms | 409 KiB | 5 Q