3v4l.org

run code in 300+ PHP versions simultaneously
<?php $f1 = function($key, $value) { if (preg_match('(_id$)i', $key) !== false) { $value = (is_array($value)) ? array_map($value, 'intval') : intval($value); } elseif (is_array($value)) { foreach ($value as $k => $v) { $value[$k] = $this->_scrubInput($k, $v); } } else { $ws = NocWorx_Validate::RX_WHITESPACE; $value = preg_replace("(^{$ws}+|{$ws}+$)", '', $value); } return $value; }; $f2 = function($name, $value) { $ws = NocWorx_Validate::RX_WHITESPACE; $body = '$v = preg_replace( \'~^' . $ws . '+|' . $ws . '+$~\', \'\', $v ); if( preg_match( \'/_id$/i\', $k ) ) { $v = intval( $v ); } return $v;'; $f = create_function( '$k, &$v', $body ); if( is_array( $value ) ) { // handle arrays of IDs if they are in a xxx_ids var if( preg_match( '/_ids$/', $name ) ) { $value = array_map( 'intval', $value ); } else { array_walk_recursive( $value, $f ); } } else { $value = $f( $name, $value ); } return $value; }; $n = ['foo', 'foo_id']; $v = [ 'hai derr', '1337!', ' hai derr ', ['a_id'=>' 42 tacos', 'b'=>'foo', 'c'=>'blurr'] ]; foreach ($n as $name) { foreach ($v as $value) { assert($f1($name, $value) === $f2($name, $value)); } }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Fatal error: Uncaught Error: Class "NocWorx_Validate" not found in /in/LBCMm:17 Stack trace: #0 /in/LBCMm(50): {closure}('foo', 'hai derr') #1 {main} thrown in /in/LBCMm on line 17
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Uncaught Error: Class "NocWorx_Validate" not found in /in/LBCMm:17 Stack trace: #0 /in/LBCMm(50): {closure}('foo', 'hai derr') #1 {main} thrown in /in/LBCMm on line 17
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught Error: Class 'NocWorx_Validate' not found in /in/LBCMm:17 Stack trace: #0 /in/LBCMm(50): {closure}('foo', 'hai derr') #1 {main} thrown in /in/LBCMm on line 17
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Fatal error: Class 'NocWorx_Validate' not found in /in/LBCMm on line 17
Process exited with code 255.

preferences:
163.65 ms | 402 KiB | 183 Q