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)); } }
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/LBCMm
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%2FLBCMm%3A3%240'
          1        ASSIGN                                                   !0, ~6
   16     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FLBCMm%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%2FLBCMm%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 = 48
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
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 = 48
Branch analysis from position: 48
Branch analysis from position: 33
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LBCMm
function name:  {closure}
number of ops:  50
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                                                      ->48
    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                                                      ->48
   11    35    >   FETCH_CLASS_CONSTANT                             ~19     'NocWorx_Validate', 'RX_WHITESPACE'
         36        ASSIGN                                                   !4, ~19
   12    37        INIT_FCALL                                               'preg_replace'
         38        ROPE_INIT                                     5  ~22     '%28%5E'
         39        ROPE_ADD                                      1  ~22     ~22, !4
         40        ROPE_ADD                                      2  ~22     ~22, '%2B%7C'
         41        ROPE_ADD                                      3  ~22     ~22, !4
         42        ROPE_END                                      4  ~21     ~22, '%2B%24%29'
         43        SEND_VAL                                                 ~21
         44        SEND_VAL                                                 ''
         45        SEND_VAR                                                 !1
         46        DO_ICALL                                         $25     
         47        ASSIGN                                                   !1, $25
   14    48    > > RETURN                                                   !1
   15    49*     > RETURN                                                   null

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

Function %00%7Bclosure%7D%2Fin%2FLBCMm%3A16%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 32
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 27
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LBCMm
function name:  {closure}
number of ops:  39
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        FETCH_CLASS_CONSTANT                             ~5      'NocWorx_Validate', 'RX_WHITESPACE'
          3        ASSIGN                                                   !2, ~5
   18     4        CONCAT                                           ~7      '%24v+%3D+preg_replace%28+%27%7E%5E', !2
          5        CONCAT                                           ~8      ~7, '%2B%7C'
          6        CONCAT                                           ~9      ~8, !2
          7        CONCAT                                           ~10     ~9, '%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'
          8        ASSIGN                                                   !3, ~10
   24     9        INIT_FCALL_BY_NAME                                       'create_function'
         10        SEND_VAL_EX                                              '%24k%2C+%26%24v'
         11        SEND_VAR_EX                                              !3
         12        DO_FCALL                                      0  $12     
         13        ASSIGN                                                   !4, $12
   26    14        TYPE_CHECK                                  128          !1
         15      > JMPZ                                                     ~14, ->32
   28    16    >   INIT_FCALL                                               'preg_match'
         17        SEND_VAL                                                 '%2F_ids%24%2F'
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                         $15     
         20      > JMPZ                                                     $15, ->27
   29    21    >   INIT_FCALL                                               'array_map'
         22        SEND_VAL                                                 'intval'
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                         $16     
         25        ASSIGN                                                   !1, $16
         26      > JMP                                                      ->31
   31    27    >   INIT_FCALL                                               'array_walk_recursive'
         28        SEND_REF                                                 !1
         29        SEND_VAR                                                 !4
         30        DO_ICALL                                                 
         31    > > JMP                                                      ->37
   34    32    >   INIT_DYNAMIC_CALL                                        !4
         33        SEND_VAR_EX                                              !0
         34        SEND_VAR_EX                                              !1
         35        DO_FCALL                                      0  $19     
         36        ASSIGN                                                   !1, $19
   37    37    > > RETURN                                                   !1
   38    38*     > RETURN                                                   null

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.48 ms | 1400 KiB | 23 Q