3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Test; class SegmentCollection { private $segmentArray = []; public function __construct(array $segmentArray) { $this->segmentArray = $segmentArray; } public function popSegment() { return array_pop($this->segmentArray); } public function shiftSegment() { return array_shift($this->segmentArray); } } interface SegmentReader { public function getNextSegment(); } abstract class SegmentReaderBase implements SegmentReader { protected $segmentCollection; public function __construct(SegmentCollection $segmentCollection) { $this->segmentCollection = $segmentCollection; } } class PopSegmentReader extends SegmentReaderBase { public function getNextSegment() { return $this->segmentCollection->popSegment(); } } class ShiftSegmentReader extends SegmentReaderBase { public function getNextSegment() { return $this->segmentCollection->shiftSegment(); } } function acceptSegmentReader(SegmentReader $segmentReader) { var_dump($segmentReader->getNextSegment()); var_dump($segmentReader->getNextSegment()); } $segmentCollection = new SegmentCollection(['foo', 'bar', 'qux', 'zip']); acceptSegmentReader(new PopSegmentReader($segmentCollection)); acceptSegmentReader(new ShiftSegmentReader($segmentCollection));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AQ2WT
function name:  (null)
number of ops:  20
compiled vars:  !0 = $segmentCollection
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   DECLARE_CLASS                                            'test%5Csegmentreaderbase'
   46     1        DECLARE_CLASS                                            'test%5Cpopsegmentreader', 'test%5Csegmentreaderbase'
   56     2        DECLARE_CLASS                                            'test%5Cshiftsegmentreader', 'test%5Csegmentreaderbase'
   72     3        NEW                                              $1      'Test%5CSegmentCollection'
          4        SEND_VAL_EX                                              <array>
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $1
   74     7        INIT_NS_FCALL_BY_NAME                                    'Test%5CacceptSegmentReader'
          8        NEW                                              $4      'Test%5CPopSegmentReader'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0          
         11        SEND_VAR_NO_REF_EX                                       $4
         12        DO_FCALL                                      0          
   75    13        INIT_NS_FCALL_BY_NAME                                    'Test%5CacceptSegmentReader'
         14        NEW                                              $7      'Test%5CShiftSegmentReader'
         15        SEND_VAR_EX                                              !0
         16        DO_FCALL                                      0          
         17        SEND_VAR_NO_REF_EX                                       $7
         18        DO_FCALL                                      0          
         19      > RETURN                                                   1

Function test%5Cacceptsegmentreader:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AQ2WT
function name:  Test\acceptSegmentReader
number of ops:  12
compiled vars:  !0 = $segmentReader
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   RECV                                             !0      
   68     1        INIT_NS_FCALL_BY_NAME                                    'Test%5Cvar_dump'
          2        INIT_METHOD_CALL                                         !0, 'getNextSegment'
          3        DO_FCALL                                      0  $1      
          4        SEND_VAR_NO_REF_EX                                       $1
          5        DO_FCALL                                      0          
   69     6        INIT_NS_FCALL_BY_NAME                                    'Test%5Cvar_dump'
          7        INIT_METHOD_CALL                                         !0, 'getNextSegment'
          8        DO_FCALL                                      0  $3      
          9        SEND_VAR_NO_REF_EX                                       $3
         10        DO_FCALL                                      0          
   70    11      > RETURN                                                   null

End of function test%5Cacceptsegmentreader

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

End of function __construct

Function popsegment:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AQ2WT
function name:  popSegment
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   INIT_NS_FCALL_BY_NAME                                    'Test%5Carray_pop'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $0      'segmentArray'
          3        SEND_FUNC_ARG                                            $0
          4        DO_FCALL                                      0  $1      
          5      > RETURN                                                   $1
   18     6*     > RETURN                                                   null

End of function popsegment

Function shiftsegment:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AQ2WT
function name:  shiftSegment
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   INIT_NS_FCALL_BY_NAME                                    'Test%5Carray_shift'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $0      'segmentArray'
          3        SEND_FUNC_ARG                                            $0
          4        DO_FCALL                                      0  $1      
          5      > RETURN                                                   $1
   23     6*     > RETURN                                                   null

End of function shiftsegment

End of class Test\SegmentCollection.

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

End of function getnextsegment

End of class Test\SegmentReader.

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

End of function __construct

End of class Test\SegmentReaderBase.

Class Test\PopSegmentReader:
Function getnextsegment:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AQ2WT
function name:  getNextSegment
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   FETCH_OBJ_R                                      ~0      'segmentCollection'
          1        INIT_METHOD_CALL                                         ~0, 'popSegment'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   52     4*     > RETURN                                                   null

End of function getnextsegment

End of class Test\PopSegmentReader.

Class Test\ShiftSegmentReader:
Function getnextsegment:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AQ2WT
function name:  getNextSegment
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   FETCH_OBJ_R                                      ~0      'segmentCollection'
          1        INIT_METHOD_CALL                                         ~0, 'shiftSegment'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   62     4*     > RETURN                                                   null

End of function getnextsegment

End of class Test\ShiftSegmentReader.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.86 ms | 1407 KiB | 21 Q