3v4l.org

run code in 300+ PHP versions simultaneously
<?php # basic test string_lt('a', 'z'); string_lt('z', 'a'); # numeric strings string_lt('22', '123'); string_lt('123', '22'); # non-numeric strings string_lt('bb', 'abc'); string_lt('abc', 'bb'); # non-numeric strings with numbers in # should be the same as "numeric strings" if strcmp() really does string comparison string_lt('22x', '123x'); string_lt('123x', '22x'); function string_lt($str1, $str2) { # < operator if ($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/MdvDq
function name:  (null)
number of ops:  33
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL_BY_NAME                                       'string_lt'
          1        SEND_VAL_EX                                              'a'
          2        SEND_VAL_EX                                              'z'
          3        DO_FCALL                                      0          
    5     4        INIT_FCALL_BY_NAME                                       'string_lt'
          5        SEND_VAL_EX                                              'z'
          6        SEND_VAL_EX                                              'a'
          7        DO_FCALL                                      0          
    8     8        INIT_FCALL_BY_NAME                                       'string_lt'
          9        SEND_VAL_EX                                              '22'
         10        SEND_VAL_EX                                              '123'
         11        DO_FCALL                                      0          
    9    12        INIT_FCALL_BY_NAME                                       'string_lt'
         13        SEND_VAL_EX                                              '123'
         14        SEND_VAL_EX                                              '22'
         15        DO_FCALL                                      0          
   12    16        INIT_FCALL_BY_NAME                                       'string_lt'
         17        SEND_VAL_EX                                              'bb'
         18        SEND_VAL_EX                                              'abc'
         19        DO_FCALL                                      0          
   13    20        INIT_FCALL_BY_NAME                                       'string_lt'
         21        SEND_VAL_EX                                              'abc'
         22        SEND_VAL_EX                                              'bb'
         23        DO_FCALL                                      0          
   17    24        INIT_FCALL_BY_NAME                                       'string_lt'
         25        SEND_VAL_EX                                              '22x'
         26        SEND_VAL_EX                                              '123x'
         27        DO_FCALL                                      0          
   18    28        INIT_FCALL_BY_NAME                                       'string_lt'
         29        SEND_VAL_EX                                              '123x'
         30        SEND_VAL_EX                                              '22x'
         31        DO_FCALL                                      0          
   47    32      > 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
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Branch analysis from position: 10
filename:       /in/MdvDq
function name:  string_lt
number of ops:  19
compiled vars:  !0 = $str1, !1 = $str2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   23     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          
   24    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          
   25    18    > > 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/MdvDq
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
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   31     2        CAST                                          6  ~4      !0
          3        CAST                                          6  ~5      !1
          4        IS_SMALLER                                       ~6      ~4, ~5
          5        ASSIGN                                                   !2, ~6
   34     6        INIT_FCALL                                               'strcmp'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $8      
         10        ASSIGN                                                   !3, $8
   36    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
   37    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/MdvDq
function name:  say
number of ops:  8
compiled vars:  !0 = $msgs, !1 = $msg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV_VARIADIC                                    !0      
   42     1      > FE_RESET_R                                       $2      !0, ->5
          2    > > FE_FETCH_R                                               $2, !1, ->5
   44     3    >   ECHO                                                     !1
   42     4      > JMP                                                      ->2
          5    >   FE_FREE                                                  $2
   46     6        ECHO                                                     '%0A'
   47     7      > RETURN                                                   null

End of function say

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.57 ms | 1404 KiB | 15 Q