3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Producto { protected $codigo; protected $nombre; protected $precio; public function __construct($codigo, $nombre, $precio) { $this->codigo = $codigo; $this->nombre = $nombre; $this->precio = $precio; } public function getPrecio(): float { return $this->precio; } public function etiqueta(): string { return $this->codigo . " · " . htmlspecialchars($this->nombre) . " · " . number_format($this->precio, 2, ',', '.') . " €"; } } class LineaPedido { private $producto; private $unidades; public function __construct($producto, $unidades) { $this->producto = $producto; $this->unidades = $unidades; } public function importe(): float { return $this->producto->getPrecio() * $this->unidades; } public function texto(): string { return $this->producto->etiqueta() . " × " . $this->unidades . " = " . number_format($this->importe(), 2, ',', '.') . " €"; } } interface Cobrable { public function total(): float; } class Pedido implements Cobrable { private $lineas = []; public function anadir(LineaPedido $linea): void { $this->lineas[] = $linea; } public function total(): float { $suma = 0.0; foreach ($this->lineas as $linea) { $suma += $linea->importe(); } return $suma; } public function ticket(): string { $texto = "Ticket · Cafetería IES Balmaseda BHI <br>"; foreach ($this->lineas as $linea) { $texto .= $linea->texto() . "<br>"; } $texto .= 'Total: ' . number_format($this->total(), 2, ',', '.') . ' €'; return $texto; } } $cafe = new Producto('B', 'Café con leche', 1.50); $bocata = new Producto('C', 'Bocadillo', 2.80); $pedido = new Pedido(); $pedido->anadir(new LineaPedido($cafe, 2)); $pedido->anadir(new LineaPedido($bocata, 1)); ?> <!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <title>TPV</title> </head> <body> <pre><?php echo $pedido->ticket(); ?></pre> </body> </html>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ag556
function name:  (null)
number of ops:  36
compiled vars:  !0 = $cafe, !1 = $bocata, !2 = $pedido
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   45     0  E >   DECLARE_CLASS                                                'pedido'
   70     1        NEW                                                  $3      'Producto'
          2        SEND_VAL_EX                                                  'B'
          3        SEND_VAL_EX                                                  'Caf%C3%A9+con+leche'
          4        SEND_VAL_EX                                                  1.5
          5        DO_FCALL                                          0          
          6        ASSIGN                                                       !0, $3
   71     7        NEW                                                  $6      'Producto'
          8        SEND_VAL_EX                                                  'C'
          9        SEND_VAL_EX                                                  'Bocadillo'
         10        SEND_VAL_EX                                                  2.8
         11        DO_FCALL                                          0          
         12        ASSIGN                                                       !1, $6
   73    13        NEW                                                  $9      'Pedido'
         14        DO_FCALL                                          0          
         15        ASSIGN                                                       !2, $9
   74    16        INIT_METHOD_CALL                                             !2, 'anadir'
         17        NEW                                                  $12     'LineaPedido'
         18        SEND_VAR_EX                                                  !0
         19        SEND_VAL_EX                                                  2
         20        DO_FCALL                                          0          
         21        SEND_VAR_NO_REF_EX                                           $12
         22        DO_FCALL                                          0          
   75    23        INIT_METHOD_CALL                                             !2, 'anadir'
         24        NEW                                                  $15     'LineaPedido'
         25        SEND_VAR_EX                                                  !1
         26        SEND_VAL_EX                                                  1
         27        DO_FCALL                                          0          
         28        SEND_VAR_NO_REF_EX                                           $15
         29        DO_FCALL                                          0          
   77    30        ECHO                                                         '%3C%21DOCTYPE+html%3E%0A%3Chtml+lang%3D%22es%22%3E%0A%3Chead%3E%0A++++%3Cmeta+charset%3D%22UTF-8%22%3E%0A++++%3Ctitle%3ETPV%3C%2Ftitle%3E%0A%3C%2Fhead%3E%0A%3Cbody%3E%0A%3Cpre%3E'
   84    31        INIT_METHOD_CALL                                             !2, 'ticket'
         32        DO_FCALL                                          0  $18     
         33        ECHO                                                         $18
         34        ECHO                                                         '%3C%2Fpre%3E%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   86    35      > RETURN                                                       1

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

End of function __construct

Function getprecio:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ag556
function name:  getPrecio
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   FETCH_OBJ_R                                          ~0      'precio'
          1        VERIFY_RETURN_TYPE                                           ~0
          2      > RETURN                                                       ~0
   16     3*       VERIFY_RETURN_TYPE                                           
          4*     > RETURN                                                       null

End of function getprecio

Function etiqueta:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ag556
function name:  etiqueta
number of ops:  21
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   FETCH_OBJ_R                                          ~0      'codigo'
          1        CONCAT                                               ~1      ~0, '+%C2%B7+'
          2        INIT_FCALL                                                   'htmlspecialchars'
          3        FETCH_OBJ_R                                          ~2      'nombre'
          4        SEND_VAL                                                     ~2
          5        DO_ICALL                                             $3      
          6        CONCAT                                               ~4      ~1, $3
          7        CONCAT                                               ~5      ~4, '+%C2%B7+'
          8        INIT_FCALL                                                   'number_format'
          9        FETCH_OBJ_R                                          ~6      'precio'
         10        SEND_VAL                                                     ~6
         11        SEND_VAL                                                     2
         12        SEND_VAL                                                     '%2C'
         13        SEND_VAL                                                     '.'
         14        DO_ICALL                                             $7      
         15        CONCAT                                               ~8      ~5, $7
         16        CONCAT                                               ~9      ~8, '+%E2%82%AC'
         17        VERIFY_RETURN_TYPE                                           ~9
         18      > RETURN                                                       ~9
   20    19*       VERIFY_RETURN_TYPE                                           
         20*     > RETURN                                                       null

End of function etiqueta

End of class Producto.

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

End of function __construct

Function importe:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ag556
function name:  importe
number of ops:  9
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   33     0  E >   FETCH_OBJ_R                                          ~0      'producto'
          1        INIT_METHOD_CALL                                             ~0, 'getPrecio'
          2        DO_FCALL                                          0  $1      
          3        FETCH_OBJ_R                                          ~2      'unidades'
          4        MUL                                                  ~3      $1, ~2
          5        VERIFY_RETURN_TYPE                                           ~3
          6      > RETURN                                                       ~3
   34     7*       VERIFY_RETURN_TYPE                                           
          8*     > RETURN                                                       null

End of function importe

Function texto:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ag556
function name:  texto
number of ops:  21
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   37     0  E >   FETCH_OBJ_R                                          ~0      'producto'
          1        INIT_METHOD_CALL                                             ~0, 'etiqueta'
          2        DO_FCALL                                          0  $1      
          3        CONCAT                                               ~2      $1, '+%C3%97+'
          4        FETCH_OBJ_R                                          ~3      'unidades'
          5        CONCAT                                               ~4      ~2, ~3
          6        CONCAT                                               ~5      ~4, '+%3D+'
          7        INIT_FCALL                                                   'number_format'
          8        INIT_METHOD_CALL                                             'importe'
          9        DO_FCALL                                          0  $6      
         10        SEND_VAR                                                     $6
         11        SEND_VAL                                                     2
         12        SEND_VAL                                                     '%2C'
         13        SEND_VAL                                                     '.'
         14        DO_ICALL                                             $7      
         15        CONCAT                                               ~8      ~5, $7
         16        CONCAT                                               ~9      ~8, '+%E2%82%AC'
         17        VERIFY_RETURN_TYPE                                           ~9
         18      > RETURN                                                       ~9
   38    19*       VERIFY_RETURN_TYPE                                           
         20*     > RETURN                                                       null

End of function texto

End of class LineaPedido.

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

End of function total

End of class Cobrable.

Class Pedido:
Function anadir:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ag556
function name:  anadir
number of ops:  5
compiled vars:  !0 = $linea
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   48     0  E >   RECV                                                 !0      
   49     1        FETCH_OBJ_W                                          $1      'lineas'
          2        ASSIGN_DIM                                                   $1
          3        OP_DATA                                                      !0
   50     4      > RETURN                                                       null

End of function anadir

Function total:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/ag556
function name:  total
number of ops:  13
compiled vars:  !0 = $suma, !1 = $linea
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   53     0  E >   ASSIGN                                                       !0, 0
   54     1        FETCH_OBJ_R                                          ~3      'lineas'
          2      > FE_RESET_R                                           $4      ~3, ->8
          3    > > FE_FETCH_R                                                   $4, !1, ->8
   55     4    >   INIT_METHOD_CALL                                             !1, 'importe'
          5        DO_FCALL                                          0  $5      
          6        ASSIGN_OP                                         1          !0, $5
   54     7      > JMP                                                          ->3
          8    >   FE_FREE                                                      $4
   57     9        VERIFY_RETURN_TYPE                                           !0
         10      > RETURN                                                       !0
   58    11*       VERIFY_RETURN_TYPE                                           
         12*     > RETURN                                                       null

End of function total

Function ticket:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/ag556
function name:  ticket
number of ops:  25
compiled vars:  !0 = $texto, !1 = $linea
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   61     0  E >   ASSIGN                                                       !0, 'Ticket+%C2%B7+Cafeter%C3%ADa+IES+Balmaseda+BHI+%3Cbr%3E'
   62     1        FETCH_OBJ_R                                          ~3      'lineas'
          2      > FE_RESET_R                                           $4      ~3, ->9
          3    > > FE_FETCH_R                                                   $4, !1, ->9
   63     4    >   INIT_METHOD_CALL                                             !1, 'texto'
          5        DO_FCALL                                          0  $5      
          6        CONCAT                                               ~6      $5, '%3Cbr%3E'
          7        ASSIGN_OP                                         8          !0, ~6
   62     8      > JMP                                                          ->3
          9    >   FE_FREE                                                      $4
   65    10        INIT_FCALL                                                   'number_format'
         11        INIT_METHOD_CALL                                             'total'
         12        DO_FCALL                                          0  $8      
         13        SEND_VAR                                                     $8
         14        SEND_VAL                                                     2
         15        SEND_VAL                                                     '%2C'
         16        SEND_VAL                                                     '.'
         17        DO_ICALL                                             $9      
         18        CONCAT                                               ~10     'Total%3A+', $9
         19        CONCAT                                               ~11     ~10, '+%E2%82%AC'
         20        ASSIGN_OP                                         8          !0, ~11
   66    21        VERIFY_RETURN_TYPE                                           !0
         22      > RETURN                                                       !0
   67    23*       VERIFY_RETURN_TYPE                                           
         24*     > RETURN                                                       null

End of function ticket

End of class Pedido.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
138.16 ms | 504 KiB | 11 Q