3v4l.org

run code in 300+ PHP versions simultaneously
<?php $methods = [ 'hello' => function(string $name) { echo sprintf('Hello %s!%s', $name, PHP_EOL); }, 'goodbye' => function(string $name) { echo sprintf('Goodbye %s!%s', $name, PHP_EOL); }, ]; /** * @method Talk hello(string $name) * @method Talk goodbye(string $name) */ class Talk { private $methods = []; public function __construct(array $methods) { $this->methods = $methods; } public function __call(string $method, array $arguments) { if ($func = $this->methods[$method] ?? false) { $func(...$arguments); return $this; } throw new \RuntimeException(sprintf('Missing %s method.')); } } $howdy = new Talk($methods); $howdy->hello('Jim')->goodbye('Joe');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iIhph
function name:  (null)
number of ops:  16
compiled vars:  !0 = $methods, !1 = $howdy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   DECLARE_LAMBDA_FUNCTION                          ~2      [0]
    6     1        INIT_ARRAY                                       ~3      ~2, 'hello'
    7     2        DECLARE_LAMBDA_FUNCTION                          ~4      [1]
    9     3        ADD_ARRAY_ELEMENT                                ~3      ~4, 'goodbye'
    3     4        ASSIGN                                                   !0, ~3
   37     5        NEW                                              $6      'Talk'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $6
   39     9        INIT_METHOD_CALL                                         !1, 'hello'
         10        SEND_VAL_EX                                              'Jim'
         11        DO_FCALL                                      0  $9      
         12        INIT_METHOD_CALL                                         $9, 'goodbye'
         13        SEND_VAL_EX                                              'Joe'
         14        DO_FCALL                                      0          
         15      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iIhph
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'sprintf'
          2        SEND_VAL                                                 'Hello+%25s%21%25s'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 '%0A'
          5        DO_ICALL                                         $1      
          6        ECHO                                                     $1
    6     7      > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iIhph
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        INIT_FCALL                                               'sprintf'
          2        SEND_VAL                                                 'Goodbye+%25s%21%25s'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 '%0A'
          5        DO_ICALL                                         $1      
          6        ECHO                                                     $1
    9     7      > RETURN                                                   null

End of Dynamic Function 1

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

End of function __construct

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/iIhph
function name:  __call
number of ops:  22
compiled vars:  !0 = $method, !1 = $arguments, !2 = $func
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   27     2        FETCH_OBJ_IS                                     ~3      'methods'
          3        FETCH_DIM_IS                                     ~4      ~3, !0
          4        COALESCE                                         ~5      ~4
          5        QM_ASSIGN                                        ~5      <false>
          6        ASSIGN                                           ~6      !2, ~5
          7      > JMPZ                                                     ~6, ->14
   28     8    >   INIT_DYNAMIC_CALL                                        !2
          9        SEND_UNPACK                                              !1
         10        CHECK_UNDEF_ARGS                                         
         11        DO_FCALL                                      1          
   30    12        FETCH_THIS                                       ~8      
         13      > RETURN                                                   ~8
   33    14    >   NEW                                              $9      'RuntimeException'
         15        INIT_FCALL                                               'sprintf'
         16        SEND_VAL                                                 'Missing+%25s+method.'
         17        DO_ICALL                                         $10     
         18        SEND_VAR_NO_REF_EX                                       $10
         19        DO_FCALL                                      0          
         20      > THROW                                         0          $9
   34    21*     > RETURN                                                   null

End of function __call

End of class Talk.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.16 ms | 1007 KiB | 14 Q