3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Php8CompatUtils { private static ?object $logger = null; public static function eq($a, $b): bool { // If both $a and $b are of type strings, compare them as strings if (is_string($a) && is_string($b)) { return $a == $b; // may not be === because php says '42' equals '042' true yet '42' === '042' is false. } // If both $a and $b are numeric strings, compare them as numbers if (is_numeric($a) && is_numeric($b)) { return $a == $b; } // If $a is an empty string and $b is 0, or vice versa, return true if (($a === '' && $b === 0) || ($a === 0 && $b === '')) { return true; } // If $a is a non-numeric string and $b is 0, or vice versa, return true if ((is_string($a) && ($a !== '') && ($b === 0)) || (($a === 0) && is_string($b) && ($b !== ''))) { return true; } // special case '123abc' == 123 .. php 7 casts 123abc to 123, then 123 == 123 results in true. lets mimic that. if ((is_string($a) && ($a !== '') && (is_numeric($b)) && ((bool)$b))) { $number = filter_var($a, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); //"-234.56xyz" return $number == $b; } if (is_numeric($a) && ((bool)$a) && is_string($b) && ($b !== '')) { $number = filter_var($b, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); //"-234.56xyz" return $a == $number; } // If $a is a number and $b is a non-numeric string, cast $a to string and compare if (is_numeric($a) && is_string($b)) { return strval($a) == $b; } // If $b is a number and $a is a non-numeric string, cast $b to string and compare if (is_string($a) && is_numeric($b)) { return $a == strval($b); } if (is_array($a) || is_array($b)) { return static::standardArrayCompare($a, $b); } // If $a and $b are both non-numeric strings, compare them directly, we should return true if they are the same return $a == $b; } public static function gt($a, $b): bool { if (static::eq($a, $b)) { return false; } return $a > $b; } public static function lt($a, $b): bool { if (static::eq($a, $b)) { return false; } return $a < $b; } public static function gte($a, $b): bool { return static::eq($a, $b) || ($a > $b); } public static function lte($a, $b): bool { return static::eq($a, $b) || ($a < $b); } private static function standardArrayCompare($op1, $op2) { if (count($op1) < count($op2)) { return -1; // $op1 < $op2 } elseif (count($op1) > count($op2)) { return 1; // $op1 > $op2 } foreach ($op1 as $key => $val) { if (!array_key_exists($key, $op2)) { return 1; } elseif (static::lt($val, $op2[$key])) { return -1; } elseif (static::gt($val, $op2[$key])) { return 1; } } return 0; // $op1 == $op2 } } $a = [0 => '']; $b = [0 => 0]; var_dump(Php8CompatUtils::eq($a, $b)); var_dump($a == $b);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k0NTK
function name:  (null)
number of ops:  14
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  106     0  E >   ASSIGN                                                   !0, <array>
  107     1        ASSIGN                                                   !1, <array>
  109     2        INIT_FCALL                                               'var_dump'
          3        INIT_STATIC_METHOD_CALL                                  'Php8CompatUtils', 'eq'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
  110     9        INIT_FCALL                                               'var_dump'
         10        IS_EQUAL                                         ~6      !0, !1
         11        SEND_VAL                                                 ~6
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Class Php8CompatUtils:
Function eq:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 18
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 46) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
2 jumps found. (Code = 47) Position 1 = 27, Position 2 = 32
Branch analysis from position: 27
2 jumps found. (Code = 46) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 34
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
2 jumps found. (Code = 46) Position 1 = 36, Position 2 = 38
Branch analysis from position: 36
2 jumps found. (Code = 46) Position 1 = 39, Position 2 = 41
Branch analysis from position: 39
2 jumps found. (Code = 47) Position 1 = 42, Position 2 = 50
Branch analysis from position: 42
2 jumps found. (Code = 46) Position 1 = 44, Position 2 = 46
Branch analysis from position: 44
2 jumps found. (Code = 46) Position 1 = 47, Position 2 = 49
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 52
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
2 jumps found. (Code = 46) Position 1 = 54, Position 2 = 56
Branch analysis from position: 54
2 jumps found. (Code = 46) Position 1 = 57, Position 2 = 61
Branch analysis from position: 57
2 jumps found. (Code = 46) Position 1 = 62, Position 2 = 64
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 74
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 74
2 jumps found. (Code = 46) Position 1 = 78, Position 2 = 80
Branch analysis from position: 78
2 jumps found. (Code = 46) Position 1 = 81, Position 2 = 83
Branch analysis from position: 81
2 jumps found. (Code = 46) Position 1 = 84, Position 2 = 86
Branch analysis from position: 84
2 jumps found. (Code = 43) Position 1 = 87, Position 2 = 96
Branch analysis from position: 87
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 96
2 jumps found. (Code = 46) Position 1 = 100, Position 2 = 102
Branch analysis from position: 100
2 jumps found. (Code = 43) Position 1 = 103, Position 2 = 107
Branch analysis from position: 103
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 107
2 jumps found. (Code = 46) Position 1 = 109, Position 2 = 113
Branch analysis from position: 109
2 jumps found. (Code = 43) Position 1 = 114, Position 2 = 118
Branch analysis from position: 114
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 118
2 jumps found. (Code = 47) Position 1 = 120, Position 2 = 122
Branch analysis from position: 120
2 jumps found. (Code = 43) Position 1 = 123, Position 2 = 129
Branch analysis from position: 123
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 129
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 122
Branch analysis from position: 113
Branch analysis from position: 102
Branch analysis from position: 86
Branch analysis from position: 83
Branch analysis from position: 80
Branch analysis from position: 64
Branch analysis from position: 61
Branch analysis from position: 56
Branch analysis from position: 49
Branch analysis from position: 46
Branch analysis from position: 50
Branch analysis from position: 41
Branch analysis from position: 38
Branch analysis from position: 31
Branch analysis from position: 32
Branch analysis from position: 26
Branch analysis from position: 18
Branch analysis from position: 6
filename:       /in/k0NTK
function name:  eq
number of ops:  134
compiled vars:  !0 = $a, !1 = $b, !2 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        TYPE_CHECK                                   64  ~3      !0
          3      > JMPZ_EX                                          ~3      ~3, ->6
          4    >   TYPE_CHECK                                   64  ~4      !1
          5        BOOL                                             ~3      ~4
          6    > > JMPZ                                                     ~3, ->10
   11     7    >   IS_EQUAL                                         ~5      !0, !1
          8        VERIFY_RETURN_TYPE                                       ~5
          9      > RETURN                                                   ~5
   15    10    >   INIT_FCALL                                               'is_numeric'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $6      
         13      > JMPZ_EX                                          ~7      $6, ->18
         14    >   INIT_FCALL                                               'is_numeric'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $8      
         17        BOOL                                             ~7      $8
         18    > > JMPZ                                                     ~7, ->22
   16    19    >   IS_EQUAL                                         ~9      !0, !1
         20        VERIFY_RETURN_TYPE                                       ~9
         21      > RETURN                                                   ~9
   20    22    >   IS_IDENTICAL                                     ~10     !0, ''
         23      > JMPZ_EX                                          ~10     ~10, ->26
         24    >   IS_IDENTICAL                                     ~11     !1, 0
         25        BOOL                                             ~10     ~11
         26    > > JMPNZ_EX                                         ~10     ~10, ->32
         27    >   IS_IDENTICAL                                     ~12     !0, 0
         28      > JMPZ_EX                                          ~12     ~12, ->31
         29    >   IS_IDENTICAL                                     ~13     !1, ''
         30        BOOL                                             ~12     ~13
         31    >   BOOL                                             ~10     ~12
         32    > > JMPZ                                                     ~10, ->34
   21    33    > > RETURN                                                   <true>
   25    34    >   TYPE_CHECK                                   64  ~14     !0
         35      > JMPZ_EX                                          ~14     ~14, ->38
         36    >   IS_NOT_IDENTICAL                                 ~15     !0, ''
         37        BOOL                                             ~14     ~15
         38    > > JMPZ_EX                                          ~14     ~14, ->41
         39    >   IS_IDENTICAL                                     ~16     !1, 0
         40        BOOL                                             ~14     ~16
         41    > > JMPNZ_EX                                         ~14     ~14, ->50
         42    >   IS_IDENTICAL                                     ~17     !0, 0
         43      > JMPZ_EX                                          ~17     ~17, ->46
         44    >   TYPE_CHECK                                   64  ~18     !1
         45        BOOL                                             ~17     ~18
         46    > > JMPZ_EX                                          ~17     ~17, ->49
         47    >   IS_NOT_IDENTICAL                                 ~19     !1, ''
         48        BOOL                                             ~17     ~19
         49    >   BOOL                                             ~14     ~17
         50    > > JMPZ                                                     ~14, ->52
   26    51    > > RETURN                                                   <true>
   30    52    >   TYPE_CHECK                                   64  ~20     !0
         53      > JMPZ_EX                                          ~20     ~20, ->56
         54    >   IS_NOT_IDENTICAL                                 ~21     !0, ''
         55        BOOL                                             ~20     ~21
         56    > > JMPZ_EX                                          ~20     ~20, ->61
         57    >   INIT_FCALL                                               'is_numeric'
         58        SEND_VAR                                                 !1
         59        DO_ICALL                                         $22     
         60        BOOL                                             ~20     $22
         61    > > JMPZ_EX                                          ~20     ~20, ->64
         62    >   BOOL                                             ~23     !1
         63        BOOL                                             ~20     ~23
         64    > > JMPZ                                                     ~20, ->74
   31    65    >   INIT_FCALL                                               'filter_var'
         66        SEND_VAR                                                 !0
         67        SEND_VAL                                                 520
         68        SEND_VAL                                                 4096
         69        DO_ICALL                                         $24     
         70        ASSIGN                                                   !2, $24
   32    71        IS_EQUAL                                         ~26     !2, !1
         72        VERIFY_RETURN_TYPE                                       ~26
         73      > RETURN                                                   ~26
   35    74    >   INIT_FCALL                                               'is_numeric'
         75        SEND_VAR                                                 !0
         76        DO_ICALL                                         $27     
         77      > JMPZ_EX                                          ~28     $27, ->80
         78    >   BOOL                                             ~29     !0
         79        BOOL                                             ~28     ~29
         80    > > JMPZ_EX                                          ~28     ~28, ->83
         81    >   TYPE_CHECK                                   64  ~30     !1
         82        BOOL                                             ~28     ~30
         83    > > JMPZ_EX                                          ~28     ~28, ->86
         84    >   IS_NOT_IDENTICAL                                 ~31     !1, ''
         85        BOOL                                             ~28     ~31
         86    > > JMPZ                                                     ~28, ->96
   36    87    >   INIT_FCALL                                               'filter_var'
         88        SEND_VAR                                                 !1
         89        SEND_VAL                                                 520
         90        SEND_VAL                                                 4096
         91        DO_ICALL                                         $32     
         92        ASSIGN                                                   !2, $32
   37    93        IS_EQUAL                                         ~34     !0, !2
         94        VERIFY_RETURN_TYPE                                       ~34
         95      > RETURN                                                   ~34
   41    96    >   INIT_FCALL                                               'is_numeric'
         97        SEND_VAR                                                 !0
         98        DO_ICALL                                         $35     
         99      > JMPZ_EX                                          ~36     $35, ->102
        100    >   TYPE_CHECK                                   64  ~37     !1
        101        BOOL                                             ~36     ~37
        102    > > JMPZ                                                     ~36, ->107
   42   103    >   CAST                                          6  ~38     !0
        104        IS_EQUAL                                         ~39     !1, ~38
        105        VERIFY_RETURN_TYPE                                       ~39
        106      > RETURN                                                   ~39
   46   107    >   TYPE_CHECK                                   64  ~40     !0
        108      > JMPZ_EX                                          ~40     ~40, ->113
        109    >   INIT_FCALL                                               'is_numeric'
        110        SEND_VAR                                                 !1
        111        DO_ICALL                                         $41     
        112        BOOL                                             ~40     $41
        113    > > JMPZ                                                     ~40, ->118
   47   114    >   CAST                                          6  ~42     !1
        115        IS_EQUAL                                         ~43     !0, ~42
        116        VERIFY_RETURN_TYPE                                       ~43
        117      > RETURN                                                   ~43
   50   118    >   TYPE_CHECK                                  128  ~44     !0
        119      > JMPNZ_EX                                         ~44     ~44, ->122
        120    >   TYPE_CHECK                                  128  ~45     !1
        121        BOOL                                             ~44     ~45
        122    > > JMPZ                                                     ~44, ->129
   51   123    >   INIT_STATIC_METHOD_CALL                                  'standardArrayCompare'
        124        SEND_VAR_EX                                              !0
        125        SEND_VAR_EX                                              !1
        126        DO_FCALL                                      0  $46     
        127        VERIFY_RETURN_TYPE                                       $46
        128      > RETURN                                                   $46
   55   129    >   IS_EQUAL                                         ~47     !0, !1
        130        VERIFY_RETURN_TYPE                                       ~47
        131      > RETURN                                                   ~47
   56   132*       VERIFY_RETURN_TYPE                                       
        133*     > RETURN                                                   null

End of function eq

Function gt:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k0NTK
function name:  gt
number of ops:  13
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   60     2        INIT_STATIC_METHOD_CALL                                  'eq'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0  $2      
          6      > JMPZ                                                     $2, ->8
   61     7    > > RETURN                                                   <false>
   64     8    >   IS_SMALLER                                       ~3      !1, !0
          9        VERIFY_RETURN_TYPE                                       ~3
         10      > RETURN                                                   ~3
   65    11*       VERIFY_RETURN_TYPE                                       
         12*     > RETURN                                                   null

End of function gt

Function lt:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k0NTK
function name:  lt
number of ops:  13
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   69     2        INIT_STATIC_METHOD_CALL                                  'eq'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0  $2      
          6      > JMPZ                                                     $2, ->8
   70     7    > > RETURN                                                   <false>
   73     8    >   IS_SMALLER                                       ~3      !0, !1
          9        VERIFY_RETURN_TYPE                                       ~3
         10      > RETURN                                                   ~3
   74    11*       VERIFY_RETURN_TYPE                                       
         12*     > RETURN                                                   null

End of function lt

Function gte:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/k0NTK
function name:  gte
number of ops:  13
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   78     2        INIT_STATIC_METHOD_CALL                                  'eq'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0  $2      
          6      > JMPNZ_EX                                         ~3      $2, ->9
          7    >   IS_SMALLER                                       ~4      !1, !0
          8        BOOL                                             ~3      ~4
          9    >   VERIFY_RETURN_TYPE                                       ~3
         10      > RETURN                                                   ~3
   79    11*       VERIFY_RETURN_TYPE                                       
         12*     > RETURN                                                   null

End of function gte

Function lte:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/k0NTK
function name:  lte
number of ops:  13
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   81     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   83     2        INIT_STATIC_METHOD_CALL                                  'eq'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0  $2      
          6      > JMPNZ_EX                                         ~3      $2, ->9
          7    >   IS_SMALLER                                       ~4      !0, !1
          8        BOOL                                             ~3      ~4
          9    >   VERIFY_RETURN_TYPE                                       ~3
         10      > RETURN                                                   ~3
   84    11*       VERIFY_RETURN_TYPE                                       
         12*     > RETURN                                                   null

End of function lte

Function standardarraycompare:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 42
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 42
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 41
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
filename:       /in/k0NTK
function name:  standardArrayCompare
number of ops:  45
compiled vars:  !0 = $op1, !1 = $op2, !2 = $val, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   86     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   88     2        COUNT                                            ~4      !0
          3        COUNT                                            ~5      !1
          4        IS_SMALLER                                               ~4, ~5
          5      > JMPZ                                                     ~6, ->8
   89     6    > > RETURN                                                   -1
   88     7*       JMP                                                      ->13
   90     8    >   COUNT                                            ~7      !0
          9        COUNT                                            ~8      !1
         10        IS_SMALLER                                               ~8, ~7
         11      > JMPZ                                                     ~9, ->13
   91    12    > > RETURN                                                   1
   93    13    > > FE_RESET_R                                       $10     !0, ->42
         14    > > FE_FETCH_R                                       ~11     $10, !2, ->42
         15    >   ASSIGN                                                   !3, ~11
   94    16        ARRAY_KEY_EXISTS                                 ~13     !3, !1
         17        BOOL_NOT                                         ~14     ~13
         18      > JMPZ                                                     ~14, ->22
   95    19    >   FE_FREE                                                  $10
         20      > RETURN                                                   1
   94    21*       JMP                                                      ->41
   96    22    >   INIT_STATIC_METHOD_CALL                                  'lt'
         23        SEND_VAR_EX                                              !2
         24        CHECK_FUNC_ARG                                           
         25        FETCH_DIM_FUNC_ARG                               $15     !1, !3
         26        SEND_FUNC_ARG                                            $15
         27        DO_FCALL                                      0  $16     
         28      > JMPZ                                                     $16, ->32
   97    29    >   FE_FREE                                                  $10
         30      > RETURN                                                   -1
   96    31*       JMP                                                      ->41
   98    32    >   INIT_STATIC_METHOD_CALL                                  'gt'
         33        SEND_VAR_EX                                              !2
         34        CHECK_FUNC_ARG                                           
         35        FETCH_DIM_FUNC_ARG                               $17     !1, !3
         36        SEND_FUNC_ARG                                            $17
         37        DO_FCALL                                      0  $18     
         38      > JMPZ                                                     $18, ->41
   99    39    >   FE_FREE                                                  $10
         40      > RETURN                                                   1
   93    41    > > JMP                                                      ->14
         42    >   FE_FREE                                                  $10
  102    43      > RETURN                                                   0
  103    44*     > RETURN                                                   null

End of function standardarraycompare

End of class Php8CompatUtils.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.96 ms | 1030 KiB | 16 Q