3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Counter { /** @return self */ public function count(); /** @return int */ public function getCount(); } class EchoingCounter implements Counter { private $counter; public function __construct(Counter $counter) { $this->counter = $counter; } public function count() { echo __METHOD__ . "\n"; $this->counter->count(); return $this; } public function getCount() { echo __METHOD__ . "\n"; return $this->counter->getCount(); } } class ImmutableCounter implements Counter { private $count; public function __construct($count = 0) { $this->count = (int) $count; } public function count() { return new ImmutableCounter($this->count + 1); } public function getCount() { return $this->count; } } $counter = new EchoingCounter(new ImmutableCounter()); $counter = $counter->count()->count()->count()->count(); echo $counter->getCount();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FuX4X
function name:  (null)
number of ops:  21
compiled vars:  !0 = $counter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   DECLARE_CLASS                                            'echoingcounter'
   37     1        DECLARE_CLASS                                            'immutablecounter'
   57     2        NEW                                              $1      'EchoingCounter'
          3        NEW                                              $2      'ImmutableCounter'
          4        DO_FCALL                                      0          
          5        SEND_VAR_NO_REF_EX                                       $2
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $1
   59     8        INIT_METHOD_CALL                                         !0, 'count'
          9        DO_FCALL                                      0  $6      
         10        INIT_METHOD_CALL                                         $6, 'count'
         11        DO_FCALL                                      0  $7      
         12        INIT_METHOD_CALL                                         $7, 'count'
         13        DO_FCALL                                      0  $8      
         14        INIT_METHOD_CALL                                         $8, 'count'
         15        DO_FCALL                                      0  $9      
         16        ASSIGN                                                   !0, $9
   61    17        INIT_METHOD_CALL                                         !0, 'getCount'
         18        DO_FCALL                                      0  $11     
         19        ECHO                                                     $11
         20      > RETURN                                                   1

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

End of function count

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

End of function getcount

End of class Counter.

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

End of function __construct

Function count:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FuX4X
function name:  count
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   ECHO                                                     'EchoingCounter%3A%3Acount%0A'
   24     1        FETCH_OBJ_R                                      ~0      'counter'
          2        INIT_METHOD_CALL                                         ~0, 'count'
          3        DO_FCALL                                      0          
   26     4        FETCH_THIS                                       ~2      
          5      > RETURN                                                   ~2
   27     6*     > RETURN                                                   null

End of function count

Function getcount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FuX4X
function name:  getCount
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ECHO                                                     'EchoingCounter%3A%3AgetCount%0A'
   33     1        FETCH_OBJ_R                                      ~0      'counter'
          2        INIT_METHOD_CALL                                         ~0, 'getCount'
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   34     5*     > RETURN                                                   null

End of function getcount

End of class EchoingCounter.

Class ImmutableCounter:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FuX4X
function name:  __construct
number of ops:  5
compiled vars:  !0 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV_INIT                                        !0      0
   43     1        CAST                                          4  ~2      !0
          2        ASSIGN_OBJ                                               'count'
          3        OP_DATA                                                  ~2
   44     4      > RETURN                                                   null

End of function __construct

Function count:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FuX4X
function name:  count
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   NEW                                              $0      'ImmutableCounter'
          1        FETCH_OBJ_R                                      ~1      'count'
          2        ADD                                              ~2      ~1, 1
          3        SEND_VAL_EX                                              ~2
          4        DO_FCALL                                      0          
          5      > RETURN                                                   $0
   49     6*     > RETURN                                                   null

End of function count

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

End of function getcount

End of class ImmutableCounter.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.39 ms | 1391 KiB | 13 Q