3v4l.org

run code in 500+ PHP versions simultaneously
<?php trait StringFunctionMapper { public Closure $substr; protected ?string $encoding = null; public function setSingleByte(): void { $this->encoding = null; $this->substr = fn (string $string, int $start, int $length = null) => \func_num_args() === 3 ? substr($string, $start, $length) : substr($string, $start); } public function setMultiByte(string $encoding = 'UTF-8'): void { $this->encoding = $encoding; $this->substr = fn (string $string, int $start, int $length = null) => mb_substr($string, $start, $length, $this->encoding); } } $temp = new class () { use StringFunctionMapper; }; $temp->setSingleByte(); var_dump(substr("search phrase", 6), ($temp->substr)("search phrase", 6), ($temp->substr)("search phrase", 6, 2)); $temp->setMultiByte(); var_dump(mb_substr("search phrase", 6), ($temp->substr)("search phrase", 6));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Wmqru
function name:  (null)
number of ops:  39
compiled vars:  !0 = $temp
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   23     0  E >   DECLARE_ANON_CLASS                                   <unknown> 
          1        NEW                                                  $2      $1
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !0, $2
   27     4        INIT_METHOD_CALL                                             !0, 'setSingleByte'
          5        DO_FCALL                                          0          
   28     6        INIT_FCALL                                                   'var_dump'
          7        FRAMELESS_ICALL_2                substr              ~6      'search+phrase', 6
          8        SEND_VAL                                                     ~6
          9        FETCH_OBJ_R                                          ~7      !0, 'substr'
         10        INIT_DYNAMIC_CALL                                            ~7
         11        SEND_VAL_EX                                                  'search+phrase'
         12        SEND_VAL_EX                                                  6
         13        DO_FCALL                                          0  $8      
         14        SEND_VAR                                                     $8
         15        FETCH_OBJ_R                                          ~9      !0, 'substr'
         16        INIT_DYNAMIC_CALL                                            ~9
         17        SEND_VAL_EX                                                  'search+phrase'
         18        SEND_VAL_EX                                                  6
         19        SEND_VAL_EX                                                  2
         20        DO_FCALL                                          0  $10     
         21        SEND_VAR                                                     $10
         22        DO_ICALL                                                     
   30    23        INIT_METHOD_CALL                                             !0, 'setMultiByte'
         24        DO_FCALL                                          0          
   31    25        INIT_FCALL                                                   'var_dump'
         26        INIT_FCALL                                                   'mb_substr'
         27        SEND_VAL                                                     'search+phrase'
         28        SEND_VAL                                                     6
         29        DO_ICALL                                             $13     
         30        SEND_VAR                                                     $13
         31        FETCH_OBJ_R                                          ~14     !0, 'substr'
         32        INIT_DYNAMIC_CALL                                            ~14
         33        SEND_VAL_EX                                                  'search+phrase'
         34        SEND_VAL_EX                                                  6
         35        DO_FCALL                                          0  $15     
         36        SEND_VAR                                                     $15
         37        DO_ICALL                                                     
         38      > RETURN                                                       1

Class StringFunctionMapper:
Function setsinglebyte:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Wmqru
function name:  setSingleByte
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   ASSIGN_OBJ                                                   'encoding'
          1        OP_DATA                                                      null
   11     2        DECLARE_LAMBDA_FUNCTION                              ~2      [0]
          3        ASSIGN_OBJ                                                   'substr'
   13     4        OP_DATA                                                      ~2
   14     5      > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Wmqru
function name:  {closure:StringFunctionMapper::setSingleByte():11}
number of ops:  14
compiled vars:  !0 = $string, !1 = $start, !2 = $length
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   11     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV_INIT                                            !2      null
          3        FUNC_NUM_ARGS                                        ~3      
          4        IS_IDENTICAL                                                 ~3, 3
          5      > JMPZ                                                         ~4, ->10
   12     6    >   FRAMELESS_ICALL_3                substr              ~5      !0, !1
          7        OP_DATA                                                      !2
          8        QM_ASSIGN                                            ~6      ~5
          9      > JMP                                                          ->12
   13    10    >   FRAMELESS_ICALL_2                substr              ~7      !0, !1
         11        QM_ASSIGN                                            ~6      ~7
         12    > > RETURN                                                       ~6
         13*     > RETURN                                                       null

End of Dynamic Function 0

End of function setsinglebyte

Function setmultibyte:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Wmqru
function name:  setMultiByte
number of ops:  7
compiled vars:  !0 = $encoding
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   RECV_INIT                                            !0      'UTF-8'
   18     1        ASSIGN_OBJ                                                   'encoding'
          2        OP_DATA                                                      !0
   19     3        DECLARE_LAMBDA_FUNCTION                              ~3      [0]
          4        ASSIGN_OBJ                                                   'substr'
          5        OP_DATA                                                      ~3
   20     6      > RETURN                                                       null


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

End of Dynamic Function 0

End of function setmultibyte

End of class StringFunctionMapper.

Class class@anonymous: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
125.94 ms | 488 KiB | 9 Q