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 = '\\s'; $value = preg_replace("(^{$ws}+|{$ws}+$)", '', $value); } return $value; }; $f2 = function($name, $value) { $ws = '\\s'; $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)); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 27
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 27
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 25
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 25
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 25
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/hSOIW
function name:  (null)
number of ops:  29
compiled vars:  !0 = $f1, !1 = $f2, !2 = $n, !3 = $v, !4 = $name, !5 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FhSOIW%3A3%240'
          1        ASSIGN                                                   !0, ~6
   16     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FhSOIW%3A16%241'
          3        ASSIGN                                                   !1, ~8
   40     4        ASSIGN                                                   !2, <array>
   41     5        ASSIGN                                                   !3, <array>
   48     6      > FE_RESET_R                                       $12     !2, ->27
          7    > > FE_FETCH_R                                               $12, !4, ->27
   49     8    > > FE_RESET_R                                       $13     !3, ->25
          9    > > FE_FETCH_R                                               $13, !5, ->25
   50    10    >   ASSERT_CHECK                                             
         11        INIT_FCALL                                               'assert'
         12        INIT_DYNAMIC_CALL                                        !0
         13        SEND_VAR_EX                                              !4
         14        SEND_VAR_EX                                              !5
         15        DO_FCALL                                      0  $14     
         16        INIT_DYNAMIC_CALL                                        !1
         17        SEND_VAR_EX                                              !4
         18        SEND_VAR_EX                                              !5
         19        DO_FCALL                                      0  $15     
         20        IS_IDENTICAL                                     ~16     $14, $15
         21        SEND_VAL                                                 ~16
         22        SEND_VAL                                                 'assert%28%24f1%28%24name%2C+%24value%29+%3D%3D%3D+%24f2%28%24name%2C+%24value%29%29'
         23        DO_ICALL                                                 
   49    24      > JMP                                                      ->9
         25    >   FE_FREE                                                  $13
   48    26      > JMP                                                      ->7
         27    >   FE_FREE                                                  $12
   52    28      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FhSOIW%3A3%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 20
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 35
Branch analysis from position: 22
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 33
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 33
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 33
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hSOIW
function name:  {closure}
number of ops:  49
compiled vars:  !0 = $key, !1 = $value, !2 = $v, !3 = $k, !4 = $ws
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        INIT_FCALL                                               'preg_match'
          3        SEND_VAL                                                 '%28_id%24%29i'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $5      
          6        TYPE_CHECK                                  1018          $5
          7      > JMPZ                                                     ~6, ->20
    5     8    >   TYPE_CHECK                                  128          !1
          9      > JMPZ                                                     ~7, ->16
         10    >   INIT_FCALL                                               'array_map'
         11        SEND_VAR                                                 !1
         12        SEND_VAL                                                 'intval'
         13        DO_ICALL                                         $8      
         14        QM_ASSIGN                                        ~9      $8
         15      > JMP                                                      ->18
         16    >   CAST                                          4  ~10     !1
         17        QM_ASSIGN                                        ~9      ~10
         18    >   ASSIGN                                                   !1, ~9
         19      > JMP                                                      ->47
    6    20    >   TYPE_CHECK                                  128          !1
         21      > JMPZ                                                     ~12, ->35
    7    22    > > FE_RESET_R                                       $13     !1, ->33
         23    > > FE_FETCH_R                                       ~14     $13, !2, ->33
         24    >   ASSIGN                                                   !3, ~14
    8    25        FETCH_THIS                                       $17     
         26        INIT_METHOD_CALL                                         $17, '_scrubInput'
         27        SEND_VAR_EX                                              !3
         28        SEND_VAR_EX                                              !2
         29        DO_FCALL                                      0  $18     
         30        ASSIGN_DIM                                               !1, !3
         31        OP_DATA                                                  $18
    7    32      > JMP                                                      ->23
         33    >   FE_FREE                                                  $13
         34      > JMP                                                      ->47
   11    35    >   ASSIGN                                                   !4, '%5Cs'
   12    36        INIT_FCALL                                               'preg_replace'
         37        ROPE_INIT                                     5  ~21     '%28%5E'
         38        ROPE_ADD                                      1  ~21     ~21, !4
         39        ROPE_ADD                                      2  ~21     ~21, '%2B%7C'
         40        ROPE_ADD                                      3  ~21     ~21, !4
         41        ROPE_END                                      4  ~20     ~21, '%2B%24%29'
         42        SEND_VAL                                                 ~20
         43        SEND_VAL                                                 ''
         44        SEND_VAR                                                 !1
         45        DO_ICALL                                         $24     
         46        ASSIGN                                                   !1, $24
   14    47    > > RETURN                                                   !1
   15    48*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FhSOIW%3A3%240

Function %00%7Bclosure%7D%2Fin%2FhSOIW%3A16%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 31
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hSOIW
function name:  {closure}
number of ops:  38
compiled vars:  !0 = $name, !1 = $value, !2 = $ws, !3 = $body, !4 = $f
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   17     2        ASSIGN                                                   !2, '%5Cs'
   18     3        CONCAT                                           ~6      '%24v+%3D+preg_replace%28+%27%7E%5E', !2
          4        CONCAT                                           ~7      ~6, '%2B%7C'
          5        CONCAT                                           ~8      ~7, !2
          6        CONCAT                                           ~9      ~8, '%2B%24%7E%27%2C+%27%27%2C+%24v+%29%3B%0A+++++++++++++if%28+preg_match%28+%27%2F_id%24%2Fi%27%2C+%24k+%29+%29+%7B%0A+++++++++++++++%24v+%3D+intval%28+%24v+%29%3B%0A+++++++++++++%7D%0A+++++++++++++return+%24v%3B'
          7        ASSIGN                                                   !3, ~9
   24     8        INIT_FCALL_BY_NAME                                       'create_function'
          9        SEND_VAL_EX                                              '%24k%2C+%26%24v'
         10        SEND_VAR_EX                                              !3
         11        DO_FCALL                                      0  $11     
         12        ASSIGN                                                   !4, $11
   26    13        TYPE_CHECK                                  128          !1
         14      > JMPZ                                                     ~13, ->31
   28    15    >   INIT_FCALL                                               'preg_match'
         16        SEND_VAL                                                 '%2F_ids%24%2F'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $14     
         19      > JMPZ                                                     $14, ->26
   29    20    >   INIT_FCALL                                               'array_map'
         21        SEND_VAL                                                 'intval'
         22        SEND_VAR                                                 !1
         23        DO_ICALL                                         $15     
         24        ASSIGN                                                   !1, $15
         25      > JMP                                                      ->30
   31    26    >   INIT_FCALL                                               'array_walk_recursive'
         27        SEND_REF                                                 !1
         28        SEND_VAR                                                 !4
         29        DO_ICALL                                                 
         30    > > JMP                                                      ->36
   34    31    >   INIT_DYNAMIC_CALL                                        !4
         32        SEND_VAR_EX                                              !0
         33        SEND_VAR_EX                                              !1
         34        DO_FCALL                                      0  $18     
         35        ASSIGN                                                   !1, $18
   37    36    > > RETURN                                                   !1
   38    37*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FhSOIW%3A16%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.37 ms | 1408 KiB | 23 Q