3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace StockExample; interface Order { public function execute(); } class StockBuy { public function __invoke() { echo "You want to buy stocks via __invoke()" . PHP_EOL; } } class StockSell { public function __invoke() { echo "You want to sell stocks __invoke()" . PHP_EOL; } } class MyCommand implements Order { private $action; public function __construct(callable $action) { $this->action = $action; } public function execute() { // Option 1) use call_user_function call_user_func($this->action); // Option 2) define it as a variable and call it by adding `()` //$action = $this->action; //$action(); } } // example with a callable object $bsc = new MyCommand(new StockBuy()); $ssc = new MyCommand(new StockSell()); $bsc->execute(); $ssc->execute();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BrKjv
function name:  (null)
number of ops:  18
compiled vars:  !0 = $bsc, !1 = $ssc
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   DECLARE_CLASS                                            'stockexample%5Cmycommand'
   47     1        NEW                                              $2      'StockExample%5CMyCommand'
          2        NEW                                              $3      'StockExample%5CStockBuy'
          3        DO_FCALL                                      0          
          4        SEND_VAR_NO_REF_EX                                       $3
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $2
   48     7        NEW                                              $7      'StockExample%5CMyCommand'
          8        NEW                                              $8      'StockExample%5CStockSell'
          9        DO_FCALL                                      0          
         10        SEND_VAR_NO_REF_EX                                       $8
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !1, $7
   49    13        INIT_METHOD_CALL                                         !0, 'execute'
         14        DO_FCALL                                      0          
   50    15        INIT_METHOD_CALL                                         !1, 'execute'
         16        DO_FCALL                                      0          
         17      > RETURN                                                   1

Class StockExample\Order:
Function execute:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BrKjv
function name:  execute
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E > > RETURN                                                   null

End of function execute

End of class StockExample\Order.

Class StockExample\StockBuy:
Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BrKjv
function name:  __invoke
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   FETCH_CONSTANT                                   ~0      'StockExample%5CPHP_EOL'
          1        CONCAT                                           ~1      'You+want+to+buy+stocks+via+__invoke%28%29', ~0
          2        ECHO                                                     ~1
   15     3      > RETURN                                                   null

End of function __invoke

End of class StockExample\StockBuy.

Class StockExample\StockSell:
Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BrKjv
function name:  __invoke
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   FETCH_CONSTANT                                   ~0      'StockExample%5CPHP_EOL'
          1        CONCAT                                           ~1      'You+want+to+sell+stocks+__invoke%28%29', ~0
          2        ECHO                                                     ~1
   23     3      > RETURN                                                   null

End of function __invoke

End of class StockExample\StockSell.

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

End of function __construct

Function execute:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BrKjv
function name:  execute
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   INIT_NS_FCALL_BY_NAME                                    'StockExample%5Ccall_user_func'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $0      'action'
          3        SEND_FUNC_ARG                                            $0
          4        DO_FCALL                                      0          
   43     5      > RETURN                                                   null

End of function execute

End of class StockExample\MyCommand.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
294.12 ms | 1015 KiB | 14 Q