3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 5.2.0 - 7.1.0
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.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.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.