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) => 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->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/j1qXn
function name:  (null)
number of ops:  32
compiled vars:  !0 = $temp
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   21     0  E >   DECLARE_ANON_CLASS                                   <unknown> 
          1        NEW                                                  $2      $1
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !0, $2
   25     4        INIT_METHOD_CALL                                             !0, 'setSingleByte'
          5        DO_FCALL                                          0          
   26     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        DO_ICALL                                                     
   28    16        INIT_METHOD_CALL                                             !0, 'setMultiByte'
         17        DO_FCALL                                          0          
   29    18        INIT_FCALL                                                   'var_dump'
         19        INIT_FCALL                                                   'mb_substr'
         20        SEND_VAL                                                     'search+phrase'
         21        SEND_VAL                                                     6
         22        DO_ICALL                                             $11     
         23        SEND_VAR                                                     $11
         24        FETCH_OBJ_R                                          ~12     !0, 'substr'
         25        INIT_DYNAMIC_CALL                                            ~12
         26        SEND_VAL_EX                                                  'search+phrase'
         27        SEND_VAL_EX                                                  6
         28        DO_FCALL                                          0  $13     
         29        SEND_VAR                                                     $13
         30        DO_ICALL                                                     
         31      > RETURN                                                       1

Class StringFunctionMapper:
Function setsinglebyte:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/j1qXn
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'
          4        OP_DATA                                                      ~2
   12     5      > 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/j1qXn
function name:  {closure:StringFunctionMapper::setSingleByte():11}
number of ops:  5
compiled vars:  !0 = $string, !1 = $start
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   11     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        FRAMELESS_ICALL_2                substr              ~2      !0, !1
          3      > RETURN                                                       ~2
          4*     > 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/j1qXn
function name:  setMultiByte
number of ops:  7
compiled vars:  !0 = $encoding
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV_INIT                                            !0      'UTF-8'
   16     1        ASSIGN_OBJ                                                   'encoding'
          2        OP_DATA                                                      !0
   17     3        DECLARE_LAMBDA_FUNCTION                              ~3      [0]
          4        ASSIGN_OBJ                                                   'substr'
          5        OP_DATA                                                      ~3
   18     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/j1qXn
function name:  {closure:StringFunctionMapper::setMultiByte():17}
number of ops:  12
compiled vars:  !0 = $string, !1 = $start, !2 = $length
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   17     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.8 ms | 484 KiB | 9 Q