3v4l.org

run code in 300+ PHP versions simultaneously
<?php $debug = 0; if (! $debug) { error_reporting(E_ERROR); } else { error_reporting(E_ALL); } $arr1 []= 'wello'; $var2 = 'woodbye wruel world'; $var3 = pack("n*", 0x77, 0x32 + 0x33, 0x6c, 0x6e-2, 0x6f); $var4 = pack('n*', 0x7765, 0x6c6c, 0x6f00); $var5 = pack('n*', 0x7765, 0x6c00, 0x6c6f); if ($debug) { echo "var3 = $var3\n"; var_dump($var4); if ($var4 == $arr1[0]) {echo "$var3 == $arr1[0]"; } if (! strcmp($var4, $arr1[0])) { echo "got a match with strcmp"; } } echo "TEsting poor_mans_strcmp()!\n"; poor_mans_strcmp('a', 'z'); poor_mans_strcmp('q111f', 'fffff'); poor_mans_strcmp($arr1, $var2); poor_mans_strcmp($arr1[0], $var2); poor_mans_strcmp($var2, $var2); poor_mans_strcmp($arr1[0], $var3); poor_mans_strcmp($arr1[0], $var4); poor_mans_strcmp($arr1[0], $var5); echo "trying the binary safe node!\n"; poor_mans_strcmp($arr1[0], $var3, 1); poor_mans_strcmp($arr1[0], $var4, 1); poor_mans_strcmp($arr1[0], $var5, 1); echo "All tests succeeeded! Ready for producktion!\n"; function poor_mans_strcmp($str1, $str2, $binary_safe = 0) { global $debug; # use old shell programming trick $str3 = 'a' . $str1; $str4 = 'a' . $str2; if ($binary_safe) { # strip null bytes to make it binary safe! $str3 = str_replace(chr(0), '', $str3); $str4 = str_replace(chr(0), '', $str4); } if ($debug) {var_dump($str3, $str4);} $result = 0; if ($str3 < $str4) { echo "$str1 is LESSTHAN $str2\n"; $result = -1; } if ($str3 > $str4) { if ($result == -1) {echo "Serious error detected, keep on trucking!\n";} $result = 1; echo "$str1 is GREATERTHAN $str2\n"; } if ($result == 0) {echo "MATCH: $str1 with $str2\n";} return $result; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 60
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 52
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 60
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
Branch analysis from position: 52
Branch analysis from position: 60
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 60
Branch analysis from position: 37
Branch analysis from position: 60
filename:       /in/1UAi2
function name:  (null)
number of ops:  125
compiled vars:  !0 = $debug, !1 = $arr1, !2 = $var2, !3 = $var3, !4 = $var4, !5 = $var5
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 0
    4     1        BOOL_NOT                                         ~7      !0
          2      > JMPZ                                                     ~7, ->7
          3    >   INIT_FCALL                                               'error_reporting'
          4        SEND_VAL                                                 1
          5        DO_ICALL                                                 
          6      > JMP                                                      ->10
    5     7    >   INIT_FCALL                                               'error_reporting'
          8        SEND_VAL                                                 32767
          9        DO_ICALL                                                 
    7    10    >   ASSIGN_DIM                                               !1
         11        OP_DATA                                                  'wello'
    8    12        ASSIGN                                                   !2, 'woodbye+wruel+world'
    9    13        INIT_FCALL                                               'pack'
         14        SEND_VAL                                                 'n%2A'
         15        SEND_VAL                                                 119
         16        SEND_VAL                                                 101
         17        SEND_VAL                                                 108
         18        SEND_VAL                                                 108
         19        SEND_VAL                                                 111
         20        DO_ICALL                                         $12     
         21        ASSIGN                                                   !3, $12
   10    22        INIT_FCALL                                               'pack'
         23        SEND_VAL                                                 'n%2A'
         24        SEND_VAL                                                 30565
         25        SEND_VAL                                                 27756
         26        SEND_VAL                                                 28416
         27        DO_ICALL                                         $14     
         28        ASSIGN                                                   !4, $14
   11    29        INIT_FCALL                                               'pack'
         30        SEND_VAL                                                 'n%2A'
         31        SEND_VAL                                                 30565
         32        SEND_VAL                                                 27648
         33        SEND_VAL                                                 27759
         34        DO_ICALL                                         $16     
         35        ASSIGN                                                   !5, $16
   14    36      > JMPZ                                                     !0, ->60
   15    37    >   ROPE_INIT                                     3  ~19     'var3+%3D+'
         38        ROPE_ADD                                      1  ~19     ~19, !3
         39        ROPE_END                                      2  ~18     ~19, '%0A'
         40        ECHO                                                     ~18
   16    41        INIT_FCALL                                               'var_dump'
         42        SEND_VAR                                                 !4
         43        DO_ICALL                                                 
   17    44        FETCH_DIM_R                                      ~22     !1, 0
         45        IS_EQUAL                                                 !4, ~22
         46      > JMPZ                                                     ~23, ->52
         47    >   ROPE_INIT                                     3  ~26     !3
         48        ROPE_ADD                                      1  ~26     ~26, '+%3D%3D+'
         49        FETCH_DIM_R                                      ~24     !1, 0
         50        ROPE_END                                      2  ~25     ~26, ~24
         51        ECHO                                                     ~25
   18    52    >   INIT_FCALL                                               'strcmp'
         53        SEND_VAR                                                 !4
         54        FETCH_DIM_R                                      ~28     !1, 0
         55        SEND_VAL                                                 ~28
         56        DO_ICALL                                         $29     
         57        BOOL_NOT                                         ~30     $29
         58      > JMPZ                                                     ~30, ->60
         59    >   ECHO                                                     'got+a+match+with+strcmp'
   21    60    >   ECHO                                                     'TEsting+poor_mans_strcmp%28%29%21%0A'
   23    61        INIT_FCALL_BY_NAME                                       'poor_mans_strcmp'
         62        SEND_VAL_EX                                              'a'
         63        SEND_VAL_EX                                              'z'
         64        DO_FCALL                                      0          
   24    65        INIT_FCALL_BY_NAME                                       'poor_mans_strcmp'
         66        SEND_VAL_EX                                              'q111f'
         67        SEND_VAL_EX                                              'fffff'
         68        DO_FCALL                                      0          
   25    69        INIT_FCALL_BY_NAME                                       'poor_mans_strcmp'
         70        SEND_VAR_EX                                              !1
         71        SEND_VAR_EX                                              !2
         72        DO_FCALL                                      0          
   26    73        INIT_FCALL_BY_NAME                                       'poor_mans_strcmp'
         74        CHECK_FUNC_ARG                                           
         75        FETCH_DIM_FUNC_ARG                               $34     !1, 0
         76        SEND_FUNC_ARG                                            $34
         77        SEND_VAR_EX                                              !2
         78        DO_FCALL                                      0          
   27    79        INIT_FCALL_BY_NAME                                       'poor_mans_strcmp'
         80        SEND_VAR_EX                                              !2
         81        SEND_VAR_EX                                              !2
         82        DO_FCALL                                      0          
   29    83        INIT_FCALL_BY_NAME                                       'poor_mans_strcmp'
         84        CHECK_FUNC_ARG                                           
         85        FETCH_DIM_FUNC_ARG                               $37     !1, 0
         86        SEND_FUNC_ARG                                            $37
         87        SEND_VAR_EX                                              !3
         88        DO_FCALL                                      0          
   30    89        INIT_FCALL_BY_NAME                                       'poor_mans_strcmp'
         90        CHECK_FUNC_ARG                                           
         91        FETCH_DIM_FUNC_ARG                               $39     !1, 0
         92        SEND_FUNC_ARG                                            $39
         93        SEND_VAR_EX                                              !4
         94        DO_FCALL                                      0          
   31    95        INIT_FCALL_BY_NAME                                       'poor_mans_strcmp'
         96        CHECK_FUNC_ARG                                           
         97        FETCH_DIM_FUNC_ARG                               $41     !1, 0
         98        SEND_FUNC_ARG                                            $41
         99        SEND_VAR_EX                                              !5
        100        DO_FCALL                                      0          
   33   101        ECHO                                                     'trying+the+binary+safe+node%21%0A'
   34   102        INIT_FCALL_BY_NAME                                       'poor_mans_strcmp'
        103        CHECK_FUNC_ARG                                           
        104        FETCH_DIM_FUNC_ARG                               $43     !1, 0
        105        SEND_FUNC_ARG                                            $43
        106        SEND_VAR_EX                                              !3
        107        SEND_VAL_EX                                              1
        108        DO_FCALL                                      0          
   35   109        INIT_FCALL_BY_NAME                                       'poor_mans_strcmp'
        110        CHECK_FUNC_ARG                                           
        111        FETCH_DIM_FUNC_ARG                               $45     !1, 0
        112        SEND_FUNC_ARG                                            $45
        113        SEND_VAR_EX                                              !4
        114        SEND_VAL_EX                                              1
        115        DO_FCALL                                      0          
   36   116        INIT_FCALL_BY_NAME                                       'poor_mans_strcmp'
        117        CHECK_FUNC_ARG                                           
        118        FETCH_DIM_FUNC_ARG                               $47     !1, 0
        119        SEND_FUNC_ARG                                            $47
        120        SEND_VAR_EX                                              !5
        121        SEND_VAL_EX                                              1
        122        DO_FCALL                                      0          
   39   123        ECHO                                                     'All+tests+succeeeded%21+Ready+for+producktion%21%0A'
   61   124      > RETURN                                                   1

Function poor_mans_strcmp:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 21
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 26
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 35
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 46
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 40
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 54
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
Branch analysis from position: 40
Branch analysis from position: 46
Branch analysis from position: 35
Branch analysis from position: 26
Branch analysis from position: 21
filename:       /in/1UAi2
function name:  poor_mans_strcmp
number of ops:  56
compiled vars:  !0 = $str1, !1 = $str2, !2 = $binary_safe, !3 = $debug, !4 = $str3, !5 = $str4, !6 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      0
   43     3        BIND_GLOBAL                                              !3, 'debug'
   45     4        CONCAT                                           ~7      'a', !0
          5        ASSIGN                                                   !4, ~7
   46     6        CONCAT                                           ~9      'a', !1
          7        ASSIGN                                                   !5, ~9
   48     8      > JMPZ                                                     !2, ->21
   51     9    >   INIT_FCALL                                               'str_replace'
         10        SEND_VAL                                                 '%00'
         11        SEND_VAL                                                 ''
         12        SEND_VAR                                                 !4
         13        DO_ICALL                                         $11     
         14        ASSIGN                                                   !4, $11
   52    15        INIT_FCALL                                               'str_replace'
         16        SEND_VAL                                                 '%00'
         17        SEND_VAL                                                 ''
         18        SEND_VAR                                                 !5
         19        DO_ICALL                                         $13     
         20        ASSIGN                                                   !5, $13
   54    21    > > JMPZ                                                     !3, ->26
         22    >   INIT_FCALL                                               'var_dump'
         23        SEND_VAR                                                 !4
         24        SEND_VAR                                                 !5
         25        DO_ICALL                                                 
   56    26    >   ASSIGN                                                   !6, 0
   57    27        IS_SMALLER                                               !4, !5
         28      > JMPZ                                                     ~17, ->35
         29    >   ROPE_INIT                                     4  ~19     !0
         30        ROPE_ADD                                      1  ~19     ~19, '+is+LESSTHAN+'
         31        ROPE_ADD                                      2  ~19     ~19, !1
         32        ROPE_END                                      3  ~18     ~19, '%0A'
         33        ECHO                                                     ~18
         34        ASSIGN                                                   !6, -1
   58    35    >   IS_SMALLER                                               !5, !4
         36      > JMPZ                                                     ~22, ->46
         37    >   IS_EQUAL                                                 !6, -1
         38      > JMPZ                                                     ~23, ->40
         39    >   ECHO                                                     'Serious+error+detected%2C+keep+on+trucking%21%0A'
         40    >   ASSIGN                                                   !6, 1
         41        ROPE_INIT                                     4  ~26     !0
         42        ROPE_ADD                                      1  ~26     ~26, '+is+GREATERTHAN+'
         43        ROPE_ADD                                      2  ~26     ~26, !1
         44        ROPE_END                                      3  ~25     ~26, '%0A'
         45        ECHO                                                     ~25
   59    46    >   IS_EQUAL                                                 !6, 0
         47      > JMPZ                                                     ~28, ->54
         48    >   ROPE_INIT                                     5  ~30     'MATCH%3A+'
         49        ROPE_ADD                                      1  ~30     ~30, !0
         50        ROPE_ADD                                      2  ~30     ~30, '+with+'
         51        ROPE_ADD                                      3  ~30     ~30, !1
         52        ROPE_END                                      4  ~29     ~30, '%0A'
         53        ECHO                                                     ~29
   60    54    > > RETURN                                                   !6
   61    55*     > RETURN                                                   null

End of function poor_mans_strcmp

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.8 ms | 1412 KiB | 23 Q