3v4l.org

run code in 500+ PHP versions simultaneously
<?php class x { /* function foo() { echo __METHOD__.PHP_EOL; } */ } $object = new x(); $method = 'foo'; $callable = [$object, $method]; //$callable(1); // Call to undefined method stdClass::foo() // No check until execution $closure = fn (...$args) => $object->$method(...$args); //$closure(1); // Call to undefined method stdClass::foo() //Call to undefined method stdClass::foo() $closure = [$object, $method](...); //Failed to create closure from callable: class stdClass does not have a method "foo" Closure::fromCallable([$object, $method]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tRUT3
function name:  (null)
number of ops:  22
compiled vars:  !0 = $object, !1 = $method, !2 = $callable, !3 = $closure
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   11     0  E >   NEW                                                  $4      'x'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $4
   12     3        ASSIGN                                                       !1, 'foo'
   14     4        INIT_ARRAY                                           ~8      !0
          5        ADD_ARRAY_ELEMENT                                    ~8      !1
          6        ASSIGN                                                       !2, ~8
   18     7        DECLARE_LAMBDA_FUNCTION                              ~10     [0]
          8        BIND_LEXICAL                                                 ~10, !0
          9        BIND_LEXICAL                                                 ~10, !1
         10        ASSIGN                                                       !3, ~10
   22    11        INIT_ARRAY                                           ~12     !0
         12        ADD_ARRAY_ELEMENT                                    ~12     !1
         13        INIT_DYNAMIC_CALL                                            ~12
         14        CALLABLE_CONVERT                                     ~13     
         15        ASSIGN                                                       !3, ~13
   25    16        INIT_STATIC_METHOD_CALL                                      'Closure', 'fromCallable'
         17        INIT_ARRAY                                           ~15     !0
         18        ADD_ARRAY_ELEMENT                                    ~15     !1
         19        SEND_VAL                                                     ~15
         20        DO_FCALL                                          0          
         21      > 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/tRUT3
function name:  {closure:/in/tRUT3:18}
number of ops:  9
compiled vars:  !0 = $args, !1 = $object, !2 = $method
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   RECV_VARIADIC                                        !0      
          1        BIND_STATIC                                                  !1
          2        BIND_STATIC                                                  !2
          3        INIT_METHOD_CALL                                             !1, !2
          4        SEND_UNPACK                                                  !0
          5        CHECK_UNDEF_ARGS                                             
          6        DO_FCALL                                          1  $3      
          7      > RETURN                                                       $3
          8*     > RETURN                                                       null

End of Dynamic Function 0

Class x: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
161.08 ms | 1487 KiB | 13 Q