3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CallableStub { protected $callback = null; public function setCallback(callable $callback) { $this->callback = $callback; } public function __call($name, $args) { if($this->callback == null || !is_callable($this->callback)) { throw new \LogicException("CallableStub requires a callback function to be callable."); } //$cb = $this->callback; // $cb(); instead and it works! return $this->callback($name, $args); } } $s = new CallableStub(); $s->setCallback( function ($x, $y) { var_dump(func_get_args()); }); $s->frankfurt('rabbit stew');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gQHkU
function name:  (null)
number of ops:  11
compiled vars:  !0 = $s
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   NEW                                              $1      'CallableStub'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   21     3        INIT_METHOD_CALL                                         !0, 'setCallback'
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FgQHkU%3A21%240'
          5        SEND_VAL_EX                                              ~4
          6        DO_FCALL                                      0          
   22     7        INIT_METHOD_CALL                                         !0, 'frankfurt'
          8        SEND_VAL_EX                                              'rabbit+stew'
          9        DO_FCALL                                      0          
         10      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FgQHkU%3A21%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gQHkU
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $x, !1 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        INIT_FCALL                                               'var_dump'
          3        FUNC_GET_ARGS                                    ~2      
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                                 
          6      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FgQHkU%3A21%240

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

End of function setcallback

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/gQHkU
function name:  __call
number of ops:  22
compiled vars:  !0 = $name, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   11     2        FETCH_OBJ_R                                      ~2      'callback'
          3        IS_EQUAL                                         ~3      ~2, null
          4      > JMPNZ_EX                                         ~3      ~3, ->11
          5    >   INIT_FCALL                                               'is_callable'
          6        FETCH_OBJ_R                                      ~4      'callback'
          7        SEND_VAL                                                 ~4
          8        DO_ICALL                                         $5      
          9        BOOL_NOT                                         ~6      $5
         10        BOOL                                             ~3      ~6
         11    > > JMPZ                                                     ~3, ->16
   12    12    >   NEW                                              $7      'LogicException'
         13        SEND_VAL_EX                                              'CallableStub+requires+a+callback+function+to+be+callable.'
         14        DO_FCALL                                      0          
         15      > THROW                                         0          $7
   16    16    >   INIT_METHOD_CALL                                         'callback'
         17        SEND_VAR_EX                                              !0
         18        SEND_VAR_EX                                              !1
         19        DO_FCALL                                      0  $9      
         20      > RETURN                                                   $9
   17    21*     > RETURN                                                   null

End of function __call

End of class CallableStub.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.09 ms | 1400 KiB | 17 Q