3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MLTemplate { protected function escape($string) { return htmlspecialchars($string, ENT_COMPAT, 'UTF-8', true); } public function substr($string, $start, $length = null) { return mb_substr($string, $start, $length, 'UTF-8'); } public function esc_substr($string, $start, $length = null) { $string = $this->escape($string); $string = $this->substr($string, $start, $length); // Make sure we haven't destroyed an html entity of the end of the string. $eos = substr($string, -10); $m = array(); if (preg_match('/&[#a-zA-Z0-9]+$/', $eos, $m)) { $len = strlen($m[0]); $string = $this->substr($string, 0, -$len); } return $string; } } header('Content-Type: text/plain; charset="utf-8"'); $mlt = new MLTemplate(); var_dump($mlt->esc_substr('uasdasdadot"Ellie"', 0, 27));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/h9og0
function name:  (null)
number of ops:  15
compiled vars:  !0 = $mlt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   INIT_FCALL                                               'header'
          1        SEND_VAL                                                 'Content-Type%3A+text%2Fplain%3B+charset%3D%22utf-8%22'
          2        DO_ICALL                                                 
   30     3        NEW                                              $2      'MLTemplate'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $2
   31     6        INIT_FCALL                                               'var_dump'
          7        INIT_METHOD_CALL                                         !0, 'esc_substr'
          8        SEND_VAL_EX                                              'uasdasdadot%22Ellie%22'
          9        SEND_VAL_EX                                              0
         10        SEND_VAL_EX                                              27
         11        DO_FCALL                                      0  $5      
         12        SEND_VAR                                                 $5
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Class MLTemplate:
Function escape:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/h9og0
function name:  escape
number of ops:  9
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'htmlspecialchars'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 2
          4        SEND_VAL                                                 'UTF-8'
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $1      
          7      > RETURN                                                   $1
    6     8*     > RETURN                                                   null

End of function escape

Function substr:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/h9og0
function name:  substr
number of ops:  11
compiled vars:  !0 = $string, !1 = $start, !2 = $length
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
    9     3        INIT_FCALL                                               'mb_substr'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        SEND_VAR                                                 !2
          7        SEND_VAL                                                 'UTF-8'
          8        DO_ICALL                                         $3      
          9      > RETURN                                                   $3
   10    10*     > RETURN                                                   null

End of function substr

Function esc_substr:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 35
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/h9og0
function name:  esc_substr
number of ops:  37
compiled vars:  !0 = $string, !1 = $start, !2 = $length, !3 = $eos, !4 = $m, !5 = $len
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
   13     3        INIT_METHOD_CALL                                         'escape'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0  $6      
          6        ASSIGN                                                   !0, $6
   14     7        INIT_METHOD_CALL                                         'substr'
          8        SEND_VAR_EX                                              !0
          9        SEND_VAR_EX                                              !1
         10        SEND_VAR_EX                                              !2
         11        DO_FCALL                                      0  $8      
         12        ASSIGN                                                   !0, $8
   17    13        INIT_FCALL                                               'substr'
         14        SEND_VAR                                                 !0
         15        SEND_VAL                                                 -10
         16        DO_ICALL                                         $10     
         17        ASSIGN                                                   !3, $10
   19    18        ASSIGN                                                   !4, <array>
   20    19        INIT_FCALL                                               'preg_match'
         20        SEND_VAL                                                 '%2F%26%5B%23a-zA-Z0-9%5D%2B%24%2F'
         21        SEND_VAR                                                 !3
         22        SEND_REF                                                 !4
         23        DO_ICALL                                         $13     
         24      > JMPZ                                                     $13, ->35
   21    25    >   FETCH_DIM_R                                      ~14     !4, 0
         26        STRLEN                                           ~15     ~14
         27        ASSIGN                                                   !5, ~15
   22    28        INIT_METHOD_CALL                                         'substr'
         29        SEND_VAR_EX                                              !0
         30        SEND_VAL_EX                                              0
         31        MUL                                              ~17     !5, -1
         32        SEND_VAL_EX                                              ~17
         33        DO_FCALL                                      0  $18     
         34        ASSIGN                                                   !0, $18
   25    35    > > RETURN                                                   !0
   26    36*     > RETURN                                                   null

End of function esc_substr

End of class MLTemplate.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.65 ms | 1400 KiB | 25 Q