3v4l.org

run code in 300+ PHP versions simultaneously
<?php say("strcmp(): Returns < 0 if str1 is less than str2;", " > 0 if str1 is greater than str2, and 0 if they are equal.", " http://php.net/manual/en/function.strcmp.php"); # basic test string_lt('a', 'z'); # numeric strings string_lt('22', '123'); # non-numeric strings string_lt('bb', 'abc'); # non-numeric strings with numbers in # should be the same as "numeric strings" if strcmp() really does string comparison string_lt('22x', '123x'); function string_lt($str1, $str2) { # < operator if ($str1 < $str2) { say("$str1 < $str2"); } if ($str2 < $str1) { say("$str2 < $str1"); } # good old strcmp() if (strcmp($str1, $str2)) { say("$str1 < $str2"); } if ($str2 < $str1) { say("$str2 < $str1"); } } function string_lt_old($str1, $str2) { # you can't use < operator for comparing strings # wacky stuff will happen $lt_says = ((string) $str1 < (string) $str2); # see what strcmp() says $strcmp_says = strcmp($str1, $str2); echo "$str1 less than $str2; lt_says: $lt_says, strcmp_says: $strcmp_says\n"; } function say(...$msgs) { foreach ($msgs as $msg) { echo $msg; } echo "\n"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GfpdE
function name:  (null)
number of ops:  22
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL_BY_NAME                                       'say'
          1        SEND_VAL_EX                                              'strcmp%28%29%3A+Returns+%3C+0+if+str1+is+less+than+str2%3B'
    4     2        SEND_VAL_EX                                              '+%3E+0+if+str1+is+greater+than+str2%2C+and+0+if+they+are+equal.'
    5     3        SEND_VAL_EX                                              '+http%3A%2F%2Fphp.net%2Fmanual%2Fen%2Ffunction.strcmp.php'
          4        DO_FCALL                                      0          
    8     5        INIT_FCALL_BY_NAME                                       'string_lt'
          6        SEND_VAL_EX                                              'a'
          7        SEND_VAL_EX                                              'z'
          8        DO_FCALL                                      0          
   12     9        INIT_FCALL_BY_NAME                                       'string_lt'
         10        SEND_VAL_EX                                              '22'
         11        SEND_VAL_EX                                              '123'
         12        DO_FCALL                                      0          
   16    13        INIT_FCALL_BY_NAME                                       'string_lt'
         14        SEND_VAL_EX                                              'bb'
         15        SEND_VAL_EX                                              'abc'
         16        DO_FCALL                                      0          
   21    17        INIT_FCALL_BY_NAME                                       'string_lt'
         18        SEND_VAL_EX                                              '22x'
         19        SEND_VAL_EX                                              '123x'
         20        DO_FCALL                                      0          
   57    21      > RETURN                                                   1

Function string_lt:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 29
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 37
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
Branch analysis from position: 29
Branch analysis from position: 18
Branch analysis from position: 10
filename:       /in/GfpdE
function name:  string_lt
number of ops:  38
compiled vars:  !0 = $str1, !1 = $str2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   28     2        IS_SMALLER                                               !0, !1
          3      > JMPZ                                                     ~2, ->10
          4    >   INIT_FCALL_BY_NAME                                       'say'
          5        ROPE_INIT                                     3  ~4      !0
          6        ROPE_ADD                                      1  ~4      ~4, '+%3C+'
          7        ROPE_END                                      2  ~3      ~4, !1
          8        SEND_VAL_EX                                              ~3
          9        DO_FCALL                                      0          
   29    10    >   IS_SMALLER                                               !1, !0
         11      > JMPZ                                                     ~7, ->18
         12    >   INIT_FCALL_BY_NAME                                       'say'
         13        ROPE_INIT                                     3  ~9      !1
         14        ROPE_ADD                                      1  ~9      ~9, '+%3C+'
         15        ROPE_END                                      2  ~8      ~9, !0
         16        SEND_VAL_EX                                              ~8
         17        DO_FCALL                                      0          
   32    18    >   INIT_FCALL                                               'strcmp'
         19        SEND_VAR                                                 !0
         20        SEND_VAR                                                 !1
         21        DO_ICALL                                         $12     
         22      > JMPZ                                                     $12, ->29
         23    >   INIT_FCALL_BY_NAME                                       'say'
         24        ROPE_INIT                                     3  ~14     !0
         25        ROPE_ADD                                      1  ~14     ~14, '+%3C+'
         26        ROPE_END                                      2  ~13     ~14, !1
         27        SEND_VAL_EX                                              ~13
         28        DO_FCALL                                      0          
   33    29    >   IS_SMALLER                                               !1, !0
         30      > JMPZ                                                     ~17, ->37
         31    >   INIT_FCALL_BY_NAME                                       'say'
         32        ROPE_INIT                                     3  ~19     !1
         33        ROPE_ADD                                      1  ~19     ~19, '+%3C+'
         34        ROPE_END                                      2  ~18     ~19, !0
         35        SEND_VAL_EX                                              ~18
         36        DO_FCALL                                      0          
   34    37    > > RETURN                                                   null

End of function string_lt

Function string_lt_old:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GfpdE
function name:  string_lt_old
number of ops:  21
compiled vars:  !0 = $str1, !1 = $str2, !2 = $lt_says, !3 = $strcmp_says
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   40     2        CAST                                          6  ~4      !0
          3        CAST                                          6  ~5      !1
          4        IS_SMALLER                                       ~6      ~4, ~5
          5        ASSIGN                                                   !2, ~6
   44     6        INIT_FCALL                                               'strcmp'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $8      
         10        ASSIGN                                                   !3, $8
   46    11        ROPE_INIT                                     8  ~11     !0
         12        ROPE_ADD                                      1  ~11     ~11, '+less+than+'
         13        ROPE_ADD                                      2  ~11     ~11, !1
         14        ROPE_ADD                                      3  ~11     ~11, '%3B+lt_says%3A+'
         15        ROPE_ADD                                      4  ~11     ~11, !2
         16        ROPE_ADD                                      5  ~11     ~11, '%2C+strcmp_says%3A+'
         17        ROPE_ADD                                      6  ~11     ~11, !3
         18        ROPE_END                                      7  ~10     ~11, '%0A'
         19        ECHO                                                     ~10
   47    20      > RETURN                                                   null

End of function string_lt_old

Function say:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 5
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
filename:       /in/GfpdE
function name:  say
number of ops:  8
compiled vars:  !0 = $msgs, !1 = $msg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV_VARIADIC                                    !0      
   52     1      > FE_RESET_R                                       $2      !0, ->5
          2    > > FE_FETCH_R                                               $2, !1, ->5
   54     3    >   ECHO                                                     !1
   52     4      > JMP                                                      ->2
          5    >   FE_FREE                                                  $2
   56     6        ECHO                                                     '%0A'
   57     7      > RETURN                                                   null

End of function say

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
196.26 ms | 1404 KiB | 15 Q