3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Str { /** PHPの組み込み関数の第一引数に使う値をプロパティとしてセット */ public function __construct( public string $str ){} /** * このクラスで外部に公開していない名前のメソッドが呼ばれた場合に動作するマジックメソッド * @see https://www.php.net/manual/ja/language.oop5.overloading.php#object.call */ public function __call($name, $arguments) { // 呼ばれたメソッド名の関数を第一引数を最初に与えたプロパティ、 // 第二引数以降を呼ばれた際の引数として実行 $result = $name($this->str, ...$arguments); // 関数の返り値が文字列ならば返り値を元に自身のインスタンスを生成して返却 // 関数の返り値が文字列でないならば返り値をそのまま返却 return is_string($result) ? new self($result) : $result; } } $s = new Str('hoge'); echo $s->substr(0, 2) ->strtoupper() ->str_pad(4, '0', STR_PAD_LEFT) ->str; // 00HO
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ejrVt
function name:  (null)
number of ops:  18
compiled vars:  !0 = $s
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   NEW                                              $1      'Str'
          1        SEND_VAL_EX                                              'hoge'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   23     4        INIT_METHOD_CALL                                         !0, 'substr'
          5        SEND_VAL_EX                                              0
          6        SEND_VAL_EX                                              2
          7        DO_FCALL                                      0  $4      
   24     8        INIT_METHOD_CALL                                         $4, 'strtoupper'
          9        DO_FCALL                                      0  $5      
   25    10        INIT_METHOD_CALL                                         $5, 'str_pad'
         11        SEND_VAL_EX                                              4
         12        SEND_VAL_EX                                              '0'
         13        SEND_VAL_EX                                              0
         14        DO_FCALL                                      0  $6      
   26    15        FETCH_OBJ_R                                      ~7      $6, 'str'
         16        ECHO                                                     ~7
   27    17      > RETURN                                                   1

Class Str:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ejrVt
function name:  __construct
number of ops:  4
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        ASSIGN_OBJ                                               'str'
          2        OP_DATA                                                  !0
    6     3      > RETURN                                                   null

End of function __construct

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ejrVt
function name:  __call
number of ops:  20
compiled vars:  !0 = $name, !1 = $arguments, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   16     2        INIT_DYNAMIC_CALL                                        !0
          3        CHECK_FUNC_ARG                                           
          4        FETCH_OBJ_FUNC_ARG                               $3      'str'
          5        SEND_FUNC_ARG                                            $3
          6        SEND_UNPACK                                              !1
          7        CHECK_UNDEF_ARGS                                         
          8        DO_FCALL                                      1  $4      
          9        ASSIGN                                                   !2, $4
   19    10        TYPE_CHECK                                   64          !2
         11      > JMPZ                                                     ~6, ->17
         12    >   NEW                          self                $7      
         13        SEND_VAR_EX                                              !2
         14        DO_FCALL                                      0          
         15        QM_ASSIGN                                        ~9      $7
         16      > JMP                                                      ->18
         17    >   QM_ASSIGN                                        ~9      !2
         18    > > RETURN                                                   ~9
   20    19*     > RETURN                                                   null

End of function __call

End of class Str.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.15 ms | 1428 KiB | 13 Q