3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Output: g 1024 error f 1024 error f 1024 error Expected Output: g 1024 error f 1024 error g 1024 error f 1024 error */ var_dump(set_error_handler('f')); $error_handler = set_error_handler('g'); var_dump($error_handler); trigger_error('error'); trigger_error('error'); function f($errno, $errstr) { echo 'f ' . $errno . ' ' . $errstr . "\n"; } function g($errno, $errstr) { echo 'g ' . $errno . ' ' . $errstr . "\n"; var_dump(set_error_handler('h')); var_dump(restore_error_handler()); global $error_handler; var_dump($error_handler); call_user_func($error_handler, $errno, $errstr); } function h($errno, $errstr) { echo 'h ' . $errno . ' ' . $errstr . "\n"; }
Output for 4.3.0 - 4.3.11, 5.0.0 - 5.0.4, 7.3.16 - 7.3.33, 7.4.4 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
NULL string(1) "f" g 1024 error NULL bool(true) string(1) "f" f 1024 error g 1024 error NULL bool(true) string(1) "f" f 1024 error
Output for 4.4.0 - 4.4.9, 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.15, 7.4.0 - 7.4.3
NULL string(1) "f" g 1024 error NULL bool(true) string(1) "f" f 1024 error f 1024 error

preferences:
79.88 ms | 2681 KiB | 4 Q