3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** strrev function implementation taken from ext/standard/string.c PHP-5-5 branch http://lxr.php.net/xref/PHP_5_5/ext/standard/string.c#3165 // {{{ proto string strrev(string str) // Reverse a string PHP_FUNCTION(strrev) { char *str; char *e, *n, *p; int str_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { return; } n = emalloc(str_len+1); p = n; e = str + str_len; while (--e>=str) { *p++ = *e; } *p = '\0'; RETVAL_STRINGL(n, str_len, 0); } // }}} */ // PHP Implementation function userland_strrev($string) { if (!is_string($string)) { return false; } $new_string = ""; $len = strlen($string); while (--$len > -1) { $new_string .= $string[$len]; } return $new_string; } $string = "Hello PHP!"; var_dump(strrev($string), userland_strrev($string)); /* for ($i = 0; $i < $n; $i++) { $t = microtime(true); $php[] = microtime(true) - $t; } */
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EOChF
function name:  (null)
number of ops:  12
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   ASSIGN                                                   !0, 'Hello+PHP%21'
   51     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'strrev'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        SEND_VAR                                                 $2
          6        INIT_FCALL                                               'userland_strrev'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0  $3      
          9        SEND_VAR                                                 $3
         10        DO_ICALL                                                 
   58    11      > RETURN                                                   1

Function userland_strrev:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 9
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 9
Branch analysis from position: 14
Branch analysis from position: 9
filename:       /in/EOChF
function name:  userland_strrev
number of ops:  16
compiled vars:  !0 = $string, !1 = $new_string, !2 = $len
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     1        TYPE_CHECK                                   64  ~3      !0
          2        BOOL_NOT                                         ~4      ~3
          3      > JMPZ                                                     ~4, ->5
   37     4    > > RETURN                                                   <false>
   40     5    >   ASSIGN                                                   !1, ''
   41     6        STRLEN                                           ~6      !0
          7        ASSIGN                                                   !2, ~6
   43     8      > JMP                                                      ->11
   44     9    >   FETCH_DIM_R                                      ~8      !0, !2
         10        ASSIGN_OP                                     8          !1, ~8
   43    11    >   PRE_DEC                                          ~10     !2
         12        IS_SMALLER                                               -1, ~10
         13      > JMPNZ                                                    ~11, ->9
   47    14    > > RETURN                                                   !1
   48    15*     > RETURN                                                   null

End of function userland_strrev

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.08 ms | 1390 KiB | 18 Q