3v4l.org

run code in 300+ PHP versions simultaneously
<?php class salutations { public function hello() { return "Hello World!"; } } class methodFactory { public function __construct($instance) { $this->package = $instance; } public function getPackageMethod($method) { if (method_exists($this->package, $method)) { $f = function() use ($method) { return $this->package->$method; }; $f->bindTo($$this); return $f; } } } $salutationsInstance = new salutations(); $obj = new methodFactory($salutationsInstance); $hello = $obj->getPackageMethod('hello'); echo $hello();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nItOk
function name:  (null)
number of ops:  15
compiled vars:  !0 = $salutationsInstance, !1 = $obj, !2 = $hello
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   NEW                                              $3      'salutations'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
   25     3        NEW                                              $6      'methodFactory'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $6
   26     7        INIT_METHOD_CALL                                         !1, 'getPackageMethod'
          8        SEND_VAL_EX                                              'hello'
          9        DO_FCALL                                      0  $9      
         10        ASSIGN                                                   !2, $9
   27    11        INIT_DYNAMIC_CALL                                        !2
         12        DO_FCALL                                      0  $11     
         13        ECHO                                                     $11
         14      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FnItOk%3A16%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nItOk
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $method
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   BIND_STATIC                                              !0
          1        FETCH_THIS                                       $1      
          2        FETCH_OBJ_R                                      ~2      $1, 'package'
          3        FETCH_OBJ_R                                      ~3      ~2, !0
          4      > RETURN                                                   ~3
          5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FnItOk%3A16%240

Class salutations:
Function hello:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nItOk
function name:  hello
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E > > RETURN                                                   'Hello+World%21'
    6     1*     > RETURN                                                   null

End of function hello

End of class salutations.

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

End of function __construct

Function getpackagemethod:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 17
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nItOk
function name:  getPackageMethod
number of ops:  18
compiled vars:  !0 = $method, !1 = $f
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        INIT_FCALL                                               'method_exists'
          2        FETCH_OBJ_R                                      ~2      'package'
          3        SEND_VAL                                                 ~2
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $3      
          6      > JMPZ                                                     $3, ->17
   16     7    >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FnItOk%3A16%240'
          8        BIND_LEXICAL                                             ~4, !0
          9        ASSIGN                                                   !1, ~4
   17    10        INIT_METHOD_CALL                                         !1, 'bindTo'
         11        CHECK_FUNC_ARG                                           
         12        FETCH_THIS                                       ~6      
         13        FETCH_FUNC_ARG               local               $7      ~6
         14        SEND_FUNC_ARG                                            $7
         15        DO_FCALL                                      0          
   18    16      > RETURN                                                   !1
   20    17    > > RETURN                                                   null

End of function getpackagemethod

End of class methodFactory.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.8 ms | 1400 KiB | 15 Q