3v4l.org

run code in 300+ PHP versions simultaneously
<?php define("TYPE", "CLI"); abstract class View { protected $imp; public function __construct() { if (TYPE == 'CLI') $this->imp = new ViewImplCli(); else if (TYPE == 'JSON') $this->imp = new ViewImplJson(); else throw new Exception('Unknown environment'); } public function addText($text) { return $this->imp->addText($text); } public function addLine() { return $this->imp->addLine(); } public function getResult() { print $this->imp->getResult(); } } class ViewContent extends View { public function printParagraph($text) { $this->addText($text); } } class ViewTable extends View { public function addCell($text) { $this->addLine(); $this->addText($text); $this->addLine(); } } abstract class ViewImpl { abstract public function addText($text); abstract public function addLine(); abstract public function getResult(); } class ViewImplCli extends ViewImpl { protected $result = ""; public function addLine() { $this->result .= str_repeat('-', 80).PHP_EOL; } public function addText($text) { $this->result .= $text.PHP_EOL; } public function getResult() { return $this->result; } } class ViewImplJson extends ViewImpl { protected $result = array(); public function addLine() { $this->result[] = array('type' => 'line'); } public function addText($text) { $this->result[] = array('type' => 'text', 'text' => $text); } public function getResult() { return json_encode($this->result); } } $content = new ViewContent(); $content->printParagraph('Hello world'); echo $content->getResult(); $table = new ViewTable(); $table->addCell('I am cell'); echo $table->getResult();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  (null)
number of ops:  23
compiled vars:  !0 = $content, !1 = $table
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'TYPE'
          2        SEND_VAL                                                 'CLI'
          3        DO_ICALL                                                 
  104     4        NEW                                              $3      'ViewContent'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $3
  105     7        INIT_METHOD_CALL                                         !0, 'printParagraph'
          8        SEND_VAL_EX                                              'Hello+world'
          9        DO_FCALL                                      0          
  106    10        INIT_METHOD_CALL                                         !0, 'getResult'
         11        DO_FCALL                                      0  $7      
         12        ECHO                                                     $7
  108    13        NEW                                              $8      'ViewTable'
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !1, $8
  109    16        INIT_METHOD_CALL                                         !1, 'addCell'
         17        SEND_VAL_EX                                              'I+am+cell'
         18        DO_FCALL                                      0          
  110    19        INIT_METHOD_CALL                                         !1, 'getResult'
         20        DO_FCALL                                      0  $12     
         21        ECHO                                                     $12
         22      > RETURN                                                   1

Class View:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 16
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/9M1Ni
function name:  __construct
number of ops:  21
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   FETCH_CONSTANT                                   ~0      'TYPE'
          1        IS_EQUAL                                                 ~0, 'CLI'
          2      > JMPZ                                                     ~1, ->8
   13     3    >   NEW                                              $3      'ViewImplCli'
          4        DO_FCALL                                      0          
          5        ASSIGN_OBJ                                               'imp'
          6        OP_DATA                                                  $3
          7      > JMP                                                      ->20
   14     8    >   FETCH_CONSTANT                                   ~5      'TYPE'
          9        IS_EQUAL                                                 ~5, 'JSON'
         10      > JMPZ                                                     ~6, ->16
   15    11    >   NEW                                              $8      'ViewImplJson'
         12        DO_FCALL                                      0          
         13        ASSIGN_OBJ                                               'imp'
         14        OP_DATA                                                  $8
         15      > JMP                                                      ->20
   17    16    >   NEW                                              $10     'Exception'
         17        SEND_VAL_EX                                              'Unknown+environment'
         18        DO_FCALL                                      0          
         19      > THROW                                         0          $10
   18    20    > > RETURN                                                   null

End of function __construct

Function addtext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  addText
number of ops:  7
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   22     1        FETCH_OBJ_R                                      ~1      'imp'
          2        INIT_METHOD_CALL                                         ~1, 'addText'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5      > RETURN                                                   $2
   23     6*     > RETURN                                                   null

End of function addtext

Function addline:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  addLine
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   FETCH_OBJ_R                                      ~0      'imp'
          1        INIT_METHOD_CALL                                         ~0, 'addLine'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   28     4*     > RETURN                                                   null

End of function addline

Function getresult:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  getResult
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   FETCH_OBJ_R                                      ~0      'imp'
          1        INIT_METHOD_CALL                                         ~0, 'getResult'
          2        DO_FCALL                                      0  $1      
          3        ECHO                                                     $1
   33     4      > RETURN                                                   null

End of function getresult

End of class View.

Class ViewContent:
Function printparagraph:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  printParagraph
number of ops:  5
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   40     1        INIT_METHOD_CALL                                         'addText'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
   41     4      > RETURN                                                   null

End of function printparagraph

Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 16
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/9M1Ni
function name:  __construct
number of ops:  21
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   FETCH_CONSTANT                                   ~0      'TYPE'
          1        IS_EQUAL                                                 ~0, 'CLI'
          2      > JMPZ                                                     ~1, ->8
   13     3    >   NEW                                              $3      'ViewImplCli'
          4        DO_FCALL                                      0          
          5        ASSIGN_OBJ                                               'imp'
          6        OP_DATA                                                  $3
          7      > JMP                                                      ->20
   14     8    >   FETCH_CONSTANT                                   ~5      'TYPE'
          9        IS_EQUAL                                                 ~5, 'JSON'
         10      > JMPZ                                                     ~6, ->16
   15    11    >   NEW                                              $8      'ViewImplJson'
         12        DO_FCALL                                      0          
         13        ASSIGN_OBJ                                               'imp'
         14        OP_DATA                                                  $8
         15      > JMP                                                      ->20
   17    16    >   NEW                                              $10     'Exception'
         17        SEND_VAL_EX                                              'Unknown+environment'
         18        DO_FCALL                                      0          
         19      > THROW                                         0          $10
   18    20    > > RETURN                                                   null

End of function __construct

Function addtext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  addText
number of ops:  7
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   22     1        FETCH_OBJ_R                                      ~1      'imp'
          2        INIT_METHOD_CALL                                         ~1, 'addText'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5      > RETURN                                                   $2
   23     6*     > RETURN                                                   null

End of function addtext

Function addline:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  addLine
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   FETCH_OBJ_R                                      ~0      'imp'
          1        INIT_METHOD_CALL                                         ~0, 'addLine'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   28     4*     > RETURN                                                   null

End of function addline

Function getresult:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  getResult
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   FETCH_OBJ_R                                      ~0      'imp'
          1        INIT_METHOD_CALL                                         ~0, 'getResult'
          2        DO_FCALL                                      0  $1      
          3        ECHO                                                     $1
   33     4      > RETURN                                                   null

End of function getresult

End of class ViewContent.

Class ViewTable:
Function addcell:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  addCell
number of ops:  9
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   48     1        INIT_METHOD_CALL                                         'addLine'
          2        DO_FCALL                                      0          
   49     3        INIT_METHOD_CALL                                         'addText'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
   50     6        INIT_METHOD_CALL                                         'addLine'
          7        DO_FCALL                                      0          
   51     8      > RETURN                                                   null

End of function addcell

Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 16
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/9M1Ni
function name:  __construct
number of ops:  21
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   FETCH_CONSTANT                                   ~0      'TYPE'
          1        IS_EQUAL                                                 ~0, 'CLI'
          2      > JMPZ                                                     ~1, ->8
   13     3    >   NEW                                              $3      'ViewImplCli'
          4        DO_FCALL                                      0          
          5        ASSIGN_OBJ                                               'imp'
          6        OP_DATA                                                  $3
          7      > JMP                                                      ->20
   14     8    >   FETCH_CONSTANT                                   ~5      'TYPE'
          9        IS_EQUAL                                                 ~5, 'JSON'
         10      > JMPZ                                                     ~6, ->16
   15    11    >   NEW                                              $8      'ViewImplJson'
         12        DO_FCALL                                      0          
         13        ASSIGN_OBJ                                               'imp'
         14        OP_DATA                                                  $8
         15      > JMP                                                      ->20
   17    16    >   NEW                                              $10     'Exception'
         17        SEND_VAL_EX                                              'Unknown+environment'
         18        DO_FCALL                                      0          
         19      > THROW                                         0          $10
   18    20    > > RETURN                                                   null

End of function __construct

Function addtext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  addText
number of ops:  7
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   22     1        FETCH_OBJ_R                                      ~1      'imp'
          2        INIT_METHOD_CALL                                         ~1, 'addText'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5      > RETURN                                                   $2
   23     6*     > RETURN                                                   null

End of function addtext

Function addline:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  addLine
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   FETCH_OBJ_R                                      ~0      'imp'
          1        INIT_METHOD_CALL                                         ~0, 'addLine'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   28     4*     > RETURN                                                   null

End of function addline

Function getresult:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  getResult
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   FETCH_OBJ_R                                      ~0      'imp'
          1        INIT_METHOD_CALL                                         ~0, 'getResult'
          2        DO_FCALL                                      0  $1      
          3        ECHO                                                     $1
   33     4      > RETURN                                                   null

End of function getresult

End of class ViewTable.

Class ViewImpl:
Function addtext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  addText
number of ops:  2
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function addtext

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

End of function addline

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

End of function getresult

End of class ViewImpl.

Class ViewImplCli:
Function addline:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  addLine
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   INIT_FCALL                                               'str_repeat'
          1        SEND_VAL                                                 '-'
          2        SEND_VAL                                                 80
          3        DO_ICALL                                         $1      
          4        CONCAT                                           ~2      $1, '%0A'
          5        ASSIGN_OBJ_OP                                 8          'result'
          6        OP_DATA                                                  ~2
   69     7      > RETURN                                                   null

End of function addline

Function addtext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  addText
number of ops:  5
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   71     0  E >   RECV                                             !0      
   73     1        CONCAT                                           ~2      !0, '%0A'
          2        ASSIGN_OBJ_OP                                 8          'result'
          3        OP_DATA                                                  ~2
   74     4      > RETURN                                                   null

End of function addtext

Function getresult:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  getResult
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   FETCH_OBJ_R                                      ~0      'result'
          1      > RETURN                                                   ~0
   79     2*     > RETURN                                                   null

End of function getresult

End of class ViewImplCli.

Class ViewImplJson:
Function addline:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  addLine
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   89     0  E >   FETCH_OBJ_W                                      $0      'result'
          1        ASSIGN_DIM                                               $0
          2        OP_DATA                                                  <array>
   90     3      > RETURN                                                   null

End of function addline

Function addtext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  addText
number of ops:  7
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   92     0  E >   RECV                                             !0      
   94     1        INIT_ARRAY                                       ~3      'text', 'type'
          2        ADD_ARRAY_ELEMENT                                ~3      !0, 'text'
          3        FETCH_OBJ_W                                      $1      'result'
          4        ASSIGN_DIM                                               $1
          5        OP_DATA                                                  ~3
   95     6      > RETURN                                                   null

End of function addtext

Function getresult:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9M1Ni
function name:  getResult
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   99     0  E >   INIT_FCALL                                               'json_encode'
          1        FETCH_OBJ_R                                      ~0      'result'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
  100     5*     > RETURN                                                   null

End of function getresult

End of class ViewImplJson.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
183.55 ms | 1420 KiB | 19 Q