3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait MetaTrait { private $methods = array(); public function addMethod($methodName, $methodCallable) { if (!is_callable($methodCallable)) { throw new InvalidArgumentException('Second param must be callable'); } $this->methods[$methodName] = Closure::bind($methodCallable, $this, get_class()); } public function __call($methodName, array $args) { if (isset($this->methods[$methodName])) { return call_user_func_array($this->methods[$methodName], $args); } throw RunTimeException('There is no method with the given name to call'); } } class HackThursday { use MetaTrait; private $dayOfWeek = 'Thursday'; } $test = new HackThursday(); $test->addMethod('fuck', function () { return 'fuck'; }); echo $test->fuck();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kth60
function name:  (null)
number of ops:  13
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   DECLARE_CLASS                                            'hackthursday'
   34     1        NEW                                              $1      'HackThursday'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   35     4        INIT_METHOD_CALL                                         !0, 'addMethod'
          5        SEND_VAL_EX                                              'fuck'
          6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fkth60%3A35%241'
   37     7        SEND_VAL_EX                                              ~4
          8        DO_FCALL                                      0          
   39     9        INIT_METHOD_CALL                                         !0, 'fuck'
         10        DO_FCALL                                      0  $6      
         11        ECHO                                                     $6
         12      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fkth60%3A35%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kth60
function name:  {closure}
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E > > RETURN                                                   'fuck'
   37     1*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fkth60%3A35%241

Class MetaTrait:
Function addmethod:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kth60
function name:  addMethod
number of ops:  22
compiled vars:  !0 = $methodName, !1 = $methodCallable
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        INIT_FCALL                                               'is_callable'
          3        SEND_VAR                                                 !1
          4        DO_ICALL                                         $2      
          5        BOOL_NOT                                         ~3      $2
          6      > JMPZ                                                     ~3, ->11
   10     7    >   NEW                                              $4      'InvalidArgumentException'
          8        SEND_VAL_EX                                              'Second+param+must+be+callable'
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $4
   12    11    >   INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
         12        SEND_VAR                                                 !1
         13        FETCH_THIS                                       ~8      
         14        SEND_VAL                                                 ~8
         15        GET_CLASS                                        ~9      
         16        SEND_VAL                                                 ~9
         17        DO_FCALL                                      0  $10     
         18        FETCH_OBJ_W                                      $6      'methods'
         19        ASSIGN_DIM                                               $6, !0
         20        OP_DATA                                                  $10
   13    21      > RETURN                                                   null

End of function addmethod

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/kth60
function name:  __call
number of ops:  17
compiled vars:  !0 = $methodName, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   17     2        FETCH_OBJ_IS                                     ~2      'methods'
          3        ISSET_ISEMPTY_DIM_OBJ                         0          ~2, !0
          4      > JMPZ                                                     ~3, ->12
   18     5    >   FETCH_OBJ_R                                      ~4      'methods'
          6        FETCH_DIM_R                                      ~5      ~4, !0
          7        INIT_USER_CALL                                0          'call_user_func_array', ~5
          8        SEND_ARRAY                                               !1
          9        CHECK_UNDEF_ARGS                                         
         10        DO_FCALL                                      0  $6      
         11      > RETURN                                                   $6
   21    12    >   INIT_FCALL_BY_NAME                                       'RunTimeException'
         13        SEND_VAL_EX                                              'There+is+no+method+with+the+given+name+to+call'
         14        DO_FCALL                                      0  $7      
         15      > THROW                                         0          $7
   22    16*     > RETURN                                                   null

End of function __call

End of class MetaTrait.

Class HackThursday: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.67 ms | 1400 KiB | 15 Q