3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Why can't I chain with just () ? */ class Foo { public $count = 0; public function __invoke() { $this->count += 1; return $this; } } $foo = new Foo(); $foo->__invoke()->__invoke()->__invoke(); echo "\n$foo->count\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Be51U
function name:  (null)
number of ops:  15
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   NEW                                              $1      'Foo'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   19     3        INIT_METHOD_CALL                                         !0, '__invoke'
          4        DO_FCALL                                      0  $4      
          5        INIT_METHOD_CALL                                         $4, '__invoke'
          6        DO_FCALL                                      0  $5      
          7        INIT_METHOD_CALL                                         $5, '__invoke'
          8        DO_FCALL                                      0          
   20     9        ROPE_INIT                                     3  ~9      '%0A'
         10        FETCH_OBJ_R                                      ~7      !0, 'count'
         11        ROPE_ADD                                      1  ~9      ~9, ~7
         12        ROPE_END                                      2  ~8      ~9, '%0A'
         13        ECHO                                                     ~8
         14      > RETURN                                                   1

Class Foo:
Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Be51U
function name:  __invoke
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ASSIGN_OBJ_OP                                 1          'count'
          1        OP_DATA                                                  1
   13     2        FETCH_THIS                                       ~1      
          3      > RETURN                                                   ~1
   14     4*     > RETURN                                                   null

End of function __invoke

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.1 ms | 1394 KiB | 13 Q