3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ok { public function t() { $this->replacer( '*' ); return preg_replace_callback( '/(t)/', array( $this, 'replacerx'), 'this is a simple test' ); } private function replacer( $input ) { static $cache = '-'; if ( ! is_array( $input ) ) { $cache = $input; } else { return $cache . $input[1] . $cache; } } } class buggyphp extends ok {} class buggyphptoo extends ok { public function t() { return parent::t(); } } $buggy = new buggyphp(); echo 'Result buggyphp: ' . $buggy->t(); echo "\n"; $buggy = new buggyphptoo(); echo 'Result buggyphptoo: ' . $buggy->t(); echo "\n"; $a = new ok(); echo 'Result ok: ' . $a->t();
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught TypeError: preg_replace_callback(): Argument #2 ($callback) must be a valid callback, class buggyphp does not have a method "replacerx" in /in/7LW7n:5 Stack trace: #0 /in/7LW7n(5): preg_replace_callback('/(t)/', Array, 'this is a simpl...') #1 /in/7LW7n(25): ok->t() #2 {main} thrown in /in/7LW7n on line 5
Process exited with code 255.
Output for 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.33, 7.4.0 - 7.4.33
Warning: preg_replace_callback(): Requires argument 2, 'buggyphp::replacerx', to be a valid callback in /in/7LW7n on line 5 Result buggyphp: this is a simple test Warning: preg_replace_callback(): Requires argument 2, 'buggyphptoo::replacerx', to be a valid callback in /in/7LW7n on line 5 Result buggyphptoo: this is a simple test Warning: preg_replace_callback(): Requires argument 2, 'ok::replacerx', to be a valid callback in /in/7LW7n on line 5 Result ok: this is a simple test
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Warning: preg_replace_callback(): requires argument 2, 'buggyphp::replacerx', to be a valid callback in /in/7LW7n on line 5 Result buggyphp: this is a simple test Warning: preg_replace_callback(): requires argument 2, 'buggyphptoo::replacerx', to be a valid callback in /in/7LW7n on line 5 Result buggyphptoo: this is a simple test Warning: preg_replace_callback(): requires argument 2, 'ok::replacerx', to be a valid callback in /in/7LW7n on line 5 Result ok: this is a simple test
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/7LW7n on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/7LW7n on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/7LW7n on line 3
Process exited with code 255.

preferences:
296.26 ms | 401 KiB | 459 Q