3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { /** @var string */ protected $bar; /** * @param string $bar */ public function __construct($bar) { $this->bar = $bar; } /** * @return null */ public function __invoke() { echo $this->bar; } } //works as expected, using __invoke() $foo = new Foo('bar'); $foo(); //works as expected, calling __invoke() (new Foo('bar'))->__invoke(); //invalid, but why !? Should work from my point of view (new Foo('bar'))();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nGuZl
function name:  (null)
number of ops:  17
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   NEW                                              $1      'Foo'
          1        SEND_VAL_EX                                              'bar'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   26     4        INIT_DYNAMIC_CALL                                        !0
          5        DO_FCALL                                      0          
   29     6        NEW                                              $5      'Foo'
          7        SEND_VAL_EX                                              'bar'
          8        DO_FCALL                                      0          
          9        INIT_METHOD_CALL                                         $5, '__invoke'
         10        DO_FCALL                                      0          
   32    11        NEW                                              $8      'Foo'
         12        SEND_VAL_EX                                              'bar'
         13        DO_FCALL                                      0          
         14        INIT_DYNAMIC_CALL                                        $8
         15        DO_FCALL                                      0          
         16      > RETURN                                                   1

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

End of function __construct

Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nGuZl
function name:  __invoke
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   FETCH_OBJ_R                                      ~0      'bar'
          1        ECHO                                                     ~0
   21     2      > RETURN                                                   null

End of function __invoke

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
130.33 ms | 1399 KiB | 13 Q