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); } } /** * I provide a unified interface to reading the segments, one at a time */ interface SegmentReaderInterface { function readSegment(); } /** * I encapsulate a SegmentContainer, my derivatives determine how to * read from it. */ 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/43gn2
function name:  (null)
number of ops:  24
compiled vars:  !0 = $segmentContainer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   DECLARE_CLASS                                            'test%5Csegmentreaderbase'
   60     1        DECLARE_CLASS                                            'test%5Cfoosegmentreader', 'test%5Csegmentreaderbase'
   70     2        DECLARE_CLASS                                            'test%5Cbarsegmentreader', 'test%5Csegmentreaderbase'
   91     3        NEW                                              $1      'Test%5CSegmentContainer'
          4        SEND_VAL_EX                                              <array>
          5        SEND_VAL_EX                                              <array>
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $1
   93     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          
   94    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          
   96    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/43gn2
function name:  Test\acceptSegmentReader
number of ops:  12
compiled vars:  !0 = $segmentReader
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   85     0  E >   RECV                                             !0      
   87     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          
   88     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          
   89    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/43gn2
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/43gn2
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/43gn2
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/43gn2
function name:  readSegment
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     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/43gn2
function name:  __construct
number of ops:  4
compiled vars:  !0 = $segmentContainer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
   50     1        ASSIGN_OBJ                                               'segmentContainer'
          2        OP_DATA                                                  !0
   51     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/43gn2
function name:  getSegmentContainer
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   FETCH_OBJ_R                                      ~0      'segmentContainer'
          1      > RETURN                                                   ~0
   56     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/43gn2
function name:  readSegment
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     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
   66     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/43gn2
function name:  readSegment
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   75     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
   76     5*     > RETURN                                                   null

End of function readsegment

End of class Test\BarSegmentReader.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.51 ms | 1473 KiB | 18 Q