3v4l.org

run code in 500+ PHP versions simultaneously
<?php function validate_length($min = 1, $max = null) { return static function ($value = null) use ($min, $max) { $len = strlen($value); if (null !== $min && $len < $min) { return false; } if (null !== $max && $len > $max) { return false; } return $value; }; } $a = [ 'a' => 'value', 'b' => '', 'c' => 'Valid' ]; $result = filter_var_array ($a, [ 'a' => ['filter' => FILTER_CALLBACK, 'options' => validate_length(null, 4)], 'b' => ['filter' => FILTER_CALLBACK, 'options' => validate_length(1)], 'c' => ['filter' => FILTER_CALLBACK, 'options' => validate_length(1, 10)] ]); var_dump($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m3isD
function name:  (null)
number of ops:  30
compiled vars:  !0 = $a, !1 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   ASSIGN                                                       !0, <array>
   25     1        INIT_FCALL                                                   'filter_var_array'
          2        SEND_VAR                                                     !0
   26     3        INIT_ARRAY                                           ~3      1024, 'filter'
          4        INIT_FCALL                                                   'validate_length'
          5        SEND_VAL                                                     null
          6        SEND_VAL                                                     4
          7        DO_FCALL                                          0  $4      
          8        ADD_ARRAY_ELEMENT                                    ~3      $4, 'options'
          9        INIT_ARRAY                                           ~5      ~3, 'a'
         10        INIT_ARRAY                                           ~6      1024, 'filter'
   27    11        INIT_FCALL                                                   'validate_length'
         12        SEND_VAL                                                     1
         13        DO_FCALL                                          0  $7      
         14        ADD_ARRAY_ELEMENT                                    ~6      $7, 'options'
         15        ADD_ARRAY_ELEMENT                                    ~5      ~6, 'b'
   26    16        INIT_ARRAY                                           ~8      1024, 'filter'
   28    17        INIT_FCALL                                                   'validate_length'
         18        SEND_VAL                                                     1
         19        SEND_VAL                                                     10
         20        DO_FCALL                                          0  $9      
         21        ADD_ARRAY_ELEMENT                                    ~8      $9, 'options'
         22        ADD_ARRAY_ELEMENT                                    ~5      ~8, 'c'
         23        SEND_VAL                                                     ~5
   25    24        DO_ICALL                                             $10     
         25        ASSIGN                                                       !1, $10
   31    26        INIT_FCALL                                                   'var_dump'
         27        SEND_VAR                                                     !1
         28        DO_ICALL                                                     
         29      > RETURN                                                       1

Function validate_length:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/m3isD
function name:  validate_length
number of ops:  7
compiled vars:  !0 = $min, !1 = $max
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV_INIT                                            !0      1
          1        RECV_INIT                                            !1      null
    5     2        DECLARE_LAMBDA_FUNCTION                              ~2      [0]
          3        BIND_LEXICAL                                                 ~2, !0
          4        BIND_LEXICAL                                                 ~2, !1
   15     5      > RETURN                                                       ~2
   16     6*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 46) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
Branch analysis from position: 9
filename:       /in/m3isD
function name:  {closure:validate_length():5}
number of ops:  19
compiled vars:  !0 = $value, !1 = $min, !2 = $max, !3 = $len
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   RECV_INIT                                            !0      null
          1        BIND_STATIC                                                  !1
          2        BIND_STATIC                                                  !2
    6     3        STRLEN                                               ~4      !0
          4        ASSIGN                                                       !3, ~4
    7     5        TYPE_CHECK                                      1020  ~6      !1
          6      > JMPZ_EX                                              ~6      ~6, ->9
          7    >   IS_SMALLER                                           ~7      !3, !1
          8        BOOL                                                 ~6      ~7
          9    > > JMPZ                                                         ~6, ->11
    8    10    > > RETURN                                                       <false>
   10    11    >   TYPE_CHECK                                      1020  ~8      !2
         12      > JMPZ_EX                                              ~8      ~8, ->15
         13    >   IS_SMALLER                                           ~9      !2, !3
         14        BOOL                                                 ~8      ~9
         15    > > JMPZ                                                         ~8, ->17
   11    16    > > RETURN                                                       <false>
   14    17    > > RETURN                                                       !0
   15    18*     > RETURN                                                       null

End of Dynamic Function 0

End of function validate_length

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
216.48 ms | 3320 KiB | 18 Q