3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * * @author Kyle @ Iezon * @copyright (c) 2016 - 2017, Iezon * * Controller for Tax and Payments * **/ namespace Iezon\Products; class Item { public function __construct($product_id) { // load product from database } public function cost() { return 1000; } } class TaxReturn { const Tax = 0.2; const TaxPercent = 20; private $_total = 0; private $_item = []; public function __construct() { $stored = $_SESSION['total']; if(empty($stored)) return; $this->_total = $stored; } public function append(Item $item) { $this->_item[] = $item; $this->_total = $this->_total + $item->cost(); return $this; } public function retrieve() { return [ 'total' => $this->_total, 'tax_total' => (($this->_total / 100) * self::Tax) + $this->_total ]; } } session_start(); $iezon = []; $iezon['payment'] = [ 'object' => new TaxReturn(), 'disclose' => [] ]; $iezon['payment']['object']->append(new Item('Some Id')); $iezon['payment']['disclose'] = $iezon['payment']['object']->retrieve(); $money = $iezon['payment']['disclose']['tax_total']; echo 'Total (' . TaxReturn::TaxPercent . '%) : ' . number_format(($money /100), 2, '.', ' ');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kdnXI
function name:  (null)
number of ops:  38
compiled vars:  !0 = $iezon, !1 = $money
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   INIT_NS_FCALL_BY_NAME                                    'Iezon%5CProducts%5Csession_start'
          1        DO_FCALL                                      0          
   54     2        ASSIGN                                                   !0, <array>
   55     3        NEW                                              $5      'Iezon%5CProducts%5CTaxReturn'
          4        DO_FCALL                                      0          
          5        INIT_ARRAY                                       ~7      $5, 'object'
          6        ADD_ARRAY_ELEMENT                                ~7      <array>, 'disclose'
          7        ASSIGN_DIM                                               !0, 'payment'
          8        OP_DATA                                                  ~7
   57     9        FETCH_DIM_R                                      ~8      !0, 'payment'
         10        FETCH_DIM_R                                      ~9      ~8, 'object'
         11        INIT_METHOD_CALL                                         ~9, 'append'
         12        NEW                                              $10     'Iezon%5CProducts%5CItem'
         13        SEND_VAL_EX                                              'Some+Id'
         14        DO_FCALL                                      0          
         15        SEND_VAR_NO_REF_EX                                       $10
         16        DO_FCALL                                      0          
   59    17        FETCH_DIM_R                                      ~15     !0, 'payment'
         18        FETCH_DIM_R                                      ~16     ~15, 'object'
         19        INIT_METHOD_CALL                                         ~16, 'retrieve'
         20        DO_FCALL                                      0  $17     
         21        FETCH_DIM_W                                      $13     !0, 'payment'
         22        ASSIGN_DIM                                               $13, 'disclose'
         23        OP_DATA                                                  $17
   61    24        FETCH_DIM_R                                      ~18     !0, 'payment'
         25        FETCH_DIM_R                                      ~19     ~18, 'disclose'
         26        FETCH_DIM_R                                      ~20     ~19, 'tax_total'
         27        ASSIGN                                                   !1, ~20
   62    28        INIT_NS_FCALL_BY_NAME                                    'Iezon%5CProducts%5Cnumber_format'
         29        DIV                                              ~22     !1, 100
         30        SEND_VAL_EX                                              ~22
         31        SEND_VAL_EX                                              2
         32        SEND_VAL_EX                                              '.'
         33        SEND_VAL_EX                                              '+'
         34        DO_FCALL                                      0  $23     
         35        CONCAT                                           ~24     'Total+%2820%25%29+%3A+', $23
         36        ECHO                                                     ~24
         37      > RETURN                                                   1

Class Iezon\Products\Item:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kdnXI
function name:  __construct
number of ops:  2
compiled vars:  !0 = $product_id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   18     1      > RETURN                                                   null

End of function __construct

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

End of function cost

End of class Iezon\Products\Item.

Class Iezon\Products\TaxReturn:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kdnXI
function name:  __construct
number of ops:  9
compiled vars:  !0 = $stored
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   FETCH_R                      global              ~1      '_SESSION'
          1        FETCH_DIM_R                                      ~2      ~1, 'total'
          2        ASSIGN                                                   !0, ~2
   36     3        ISSET_ISEMPTY_CV                                         !0
          4      > JMPZ                                                     ~4, ->6
          5    > > RETURN                                                   null
   37     6    >   ASSIGN_OBJ                                               '_total'
          7        OP_DATA                                                  !0
   38     8      > RETURN                                                   null

End of function __construct

Function append:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kdnXI
function name:  append
number of ops:  13
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   41     1        FETCH_OBJ_W                                      $1      '_item'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   42     4        FETCH_OBJ_R                                      ~4      '_total'
          5        INIT_METHOD_CALL                                         !0, 'cost'
          6        DO_FCALL                                      0  $5      
          7        ADD                                              ~6      ~4, $5
          8        ASSIGN_OBJ                                               '_total'
          9        OP_DATA                                                  ~6
   43    10        FETCH_THIS                                       ~7      
         11      > RETURN                                                   ~7
   44    12*     > RETURN                                                   null

End of function append

Function retrieve:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kdnXI
function name:  retrieve
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   FETCH_OBJ_R                                      ~0      '_total'
          1        INIT_ARRAY                                       ~1      ~0, 'total'
          2        FETCH_OBJ_R                                      ~2      '_total'
          3        DIV                                              ~3      ~2, 100
          4        FETCH_CLASS_CONSTANT                             ~4      'Tax'
          5        MUL                                              ~5      ~3, ~4
          6        FETCH_OBJ_R                                      ~6      '_total'
          7        ADD                                              ~7      ~5, ~6
          8        ADD_ARRAY_ELEMENT                                ~1      ~7, 'tax_total'
          9      > RETURN                                                   ~1
   48    10*     > RETURN                                                   null

End of function retrieve

End of class Iezon\Products\TaxReturn.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.89 ms | 1404 KiB | 17 Q