3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Test; class SegmentContainer { private $fooSegmentArray = []; private $barSegmentArray = []; public function __construct(array $fooSegmentArray, array $barSegmentArray) { $this->fooSegmentArray = $fooSegmentArray; $this->barSegmentArray = $barSegmentArray; } public function popFooSegment() { return array_pop($this->fooSegmentArray); } public function shiftBarSegment() { return array_shift($this->barSegmentArray); } } interface SegmentReaderInterface { function readSegment(); } abstract class SegmentReaderBase implements SegmentReaderInterface { private $segmentContainer; public function __construct(SegmentContainer $segmentContainer) { $this->segmentContainer = $segmentContainer; } public function getSegmentContainer() { return $this->segmentContainer; } } class FooSegmentReader extends SegmentReaderBase { public function readSegment() { return $this->getSegmentContainer()->popFooSegment(); } } class BarSegmentReader extends SegmentReaderBase { public function readSegment() { return $this->getSegmentContainer()->shiftBarSegment(); } } /** * I don't care whether I end up reading from the $fooSegmentArray or * the $barSegmentArray, nor the direction from which I'm reading it. * I just want to be able to read them, one at a time. */ function acceptSegmentReader(SegmentReaderInterface $segmentReader) { var_dump($segmentReader->readSegment()); var_dump($segmentReader->readSegment()); } $segmentContainer = new SegmentContainer(['a', 'b', 'c'], ['1', '2', '3']); acceptSegmentReader(new FooSegmentReader($segmentContainer)); acceptSegmentReader(new BarSegmentReader($segmentContainer)); var_dump($segmentContainer);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ugQVX
function name:  (null)
number of ops:  24
compiled vars:  !0 = $segmentContainer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   DECLARE_CLASS                                            'test%5Csegmentreaderbase'
   53     1        DECLARE_CLASS                                            'test%5Cfoosegmentreader', 'test%5Csegmentreaderbase'
   63     2        DECLARE_CLASS                                            'test%5Cbarsegmentreader', 'test%5Csegmentreaderbase'
   84     3        NEW                                              $1      'Test%5CSegmentContainer'
          4        SEND_VAL_EX                                              <array>
          5        SEND_VAL_EX                                              <array>
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $1
   86     8        INIT_NS_FCALL_BY_NAME                                    'Test%5CacceptSegmentReader'
          9        NEW                                              $4      'Test%5CFooSegmentReader'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0          
         12        SEND_VAR_NO_REF_EX                                       $4
         13        DO_FCALL                                      0          
   87    14        INIT_NS_FCALL_BY_NAME                                    'Test%5CacceptSegmentReader'
         15        NEW                                              $7      'Test%5CBarSegmentReader'
         16        SEND_VAR_EX                                              !0
         17        DO_FCALL                                      0          
         18        SEND_VAR_NO_REF_EX                                       $7
         19        DO_FCALL                                      0          
   89    20        INIT_NS_FCALL_BY_NAME                                    'Test%5Cvar_dump'
         21        SEND_VAR_EX                                              !0
         22        DO_FCALL                                      0          
         23      > RETURN                                                   1

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

End of function test%5Cacceptsegmentreader

Class Test\SegmentContainer:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ugQVX
function name:  __construct
number of ops:  7
compiled vars:  !0 = $fooSegmentArray, !1 = $barSegmentArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2        ASSIGN_OBJ                                               'fooSegmentArray'
          3        OP_DATA                                                  !0
   14     4        ASSIGN_OBJ                                               'barSegmentArray'
          5        OP_DATA                                                  !1
   15     6      > RETURN                                                   null

End of function __construct

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

End of function popfoosegment

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

End of function shiftbarsegment

End of class Test\SegmentContainer.

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

End of function readsegment

End of class Test\SegmentReaderInterface.

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

End of function __construct

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

End of function getsegmentcontainer

End of class Test\SegmentReaderBase.

Class Test\FooSegmentReader:
Function readsegment:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ugQVX
function name:  readSegment
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   INIT_METHOD_CALL                                         'getSegmentContainer'
          1        DO_FCALL                                      0  $0      
          2        INIT_METHOD_CALL                                         $0, 'popFooSegment'
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   59     5*     > RETURN                                                   null

End of function readsegment

End of class Test\FooSegmentReader.

Class Test\BarSegmentReader:
Function readsegment:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ugQVX
function name:  readSegment
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   INIT_METHOD_CALL                                         'getSegmentContainer'
          1        DO_FCALL                                      0  $0      
          2        INIT_METHOD_CALL                                         $0, 'shiftBarSegment'
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   69     5*     > RETURN                                                   null

End of function readsegment

End of class Test\BarSegmentReader.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.85 ms | 1398 KiB | 21 Q