3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Price { protected $value; public function __construct($value) { $this->value = $value; } // Duck typing means this declaration is actually optional abstract protected function getRawValue(); public function getFormattedValue() { // Calls a protected method of whichever child class is $this return number_format($this->getRawValue(), 2); } public function add(Price $other) { // Calls a protected method of whichever child class is $other $this->value += $other->getRawValue(); } } class TaxFreePrice extends Price { protected function getRawValue() { return $this->value; } } class PriceWithTax extends Price{ const TAX_RATE=1.2; protected function getRawValue() { return $this->value * self::TAX_RATE; } } $a = new TaxFreePrice(10); $b = new PriceWithTax(10); echo $a->getFormattedValue(), PHP_EOL; echo $b->getFormattedValue(), PHP_EOL; // Here, an instance of TaxFreePrice will access a protected member of PriceWithTax $a->add($b); echo $a->getFormattedValue(), PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LeClo
function name:  (null)
number of ops:  24
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   NEW                                              $2      'TaxFreePrice'
          1        SEND_VAL_EX                                              10
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   39     4        NEW                                              $5      'PriceWithTax'
          5        SEND_VAL_EX                                              10
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $5
   40     8        INIT_METHOD_CALL                                         !0, 'getFormattedValue'
          9        DO_FCALL                                      0  $8      
         10        ECHO                                                     $8
         11        ECHO                                                     '%0A'
   41    12        INIT_METHOD_CALL                                         !1, 'getFormattedValue'
         13        DO_FCALL                                      0  $9      
         14        ECHO                                                     $9
         15        ECHO                                                     '%0A'
   44    16        INIT_METHOD_CALL                                         !0, 'add'
         17        SEND_VAR_EX                                              !1
         18        DO_FCALL                                      0          
   45    19        INIT_METHOD_CALL                                         !0, 'getFormattedValue'
         20        DO_FCALL                                      0  $11     
         21        ECHO                                                     $11
         22        ECHO                                                     '%0A'
   46    23      > RETURN                                                   1

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

End of function __construct

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

End of function getrawvalue

Function getformattedvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LeClo
function name:  getFormattedValue
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'number_format'
          1        INIT_METHOD_CALL                                         'getRawValue'
          2        DO_FCALL                                      0  $0      
          3        SEND_VAR                                                 $0
          4        SEND_VAL                                                 2
          5        DO_ICALL                                         $1      
          6      > RETURN                                                   $1
   16     7*     > RETURN                                                   null

End of function getformattedvalue

Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LeClo
function name:  add
number of ops:  6
compiled vars:  !0 = $other
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   20     1        INIT_METHOD_CALL                                         !0, 'getRawValue'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN_OBJ_OP                                 1          'value'
          4        OP_DATA                                                  $2
   21     5      > RETURN                                                   null

End of function add

End of class Price.

Class TaxFreePrice:
Function getrawvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LeClo
function name:  getRawValue
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   FETCH_OBJ_R                                      ~0      'value'
          1      > RETURN                                                   ~0
   27     2*     > RETURN                                                   null

End of function getrawvalue

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

End of function __construct

Function getformattedvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LeClo
function name:  getFormattedValue
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'number_format'
          1        INIT_METHOD_CALL                                         'getRawValue'
          2        DO_FCALL                                      0  $0      
          3        SEND_VAR                                                 $0
          4        SEND_VAL                                                 2
          5        DO_ICALL                                         $1      
          6      > RETURN                                                   $1
   16     7*     > RETURN                                                   null

End of function getformattedvalue

Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LeClo
function name:  add
number of ops:  6
compiled vars:  !0 = $other
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   20     1        INIT_METHOD_CALL                                         !0, 'getRawValue'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN_OBJ_OP                                 1          'value'
          4        OP_DATA                                                  $2
   21     5      > RETURN                                                   null

End of function add

End of class TaxFreePrice.

Class PriceWithTax:
Function getrawvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LeClo
function name:  getRawValue
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   FETCH_OBJ_R                                      ~0      'value'
          1        MUL                                              ~1      ~0, 1.2
          2      > RETURN                                                   ~1
   35     3*     > RETURN                                                   null

End of function getrawvalue

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

End of function __construct

Function getformattedvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LeClo
function name:  getFormattedValue
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'number_format'
          1        INIT_METHOD_CALL                                         'getRawValue'
          2        DO_FCALL                                      0  $0      
          3        SEND_VAR                                                 $0
          4        SEND_VAL                                                 2
          5        DO_ICALL                                         $1      
          6      > RETURN                                                   $1
   16     7*     > RETURN                                                   null

End of function getformattedvalue

Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LeClo
function name:  add
number of ops:  6
compiled vars:  !0 = $other
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   20     1        INIT_METHOD_CALL                                         !0, 'getRawValue'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN_OBJ_OP                                 1          'value'
          4        OP_DATA                                                  $2
   21     5      > RETURN                                                   null

End of function add

End of class PriceWithTax.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.79 ms | 1408 KiB | 15 Q