3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Carro { protected $productos = array (); public function add ( $producto, $cantidad ) { $this->productos[$producto] = $cantidad; } public function what_inside_cart () { $cadena = ""; array_walk ( $this->productos, function ( $cantidad, $producto ) use ( &$cadena ) { $cadena .= $producto . " -> " . $cantidad . "\r\n"; }); return $cadena; } } $mi_carro = new Carro; // Añadir algunos artículos al carro $mi_carro->add ( 'mantequilla', 1 ); $mi_carro->add ( 'leche', 3 ); $mi_carro->add ( 'huevos', 6 ); //echo $mi_carro->productos[0]; // al ser protected, dará error echo $mi_carro->what_inside_cart ();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nCn27
function name:  (null)
number of ops:  19
compiled vars:  !0 = $mi_carro
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   NEW                                              $1      'Carro'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   26     3        INIT_METHOD_CALL                                         !0, 'add'
          4        SEND_VAL_EX                                              'mantequilla'
          5        SEND_VAL_EX                                              1
          6        DO_FCALL                                      0          
   27     7        INIT_METHOD_CALL                                         !0, 'add'
          8        SEND_VAL_EX                                              'leche'
          9        SEND_VAL_EX                                              3
         10        DO_FCALL                                      0          
   28    11        INIT_METHOD_CALL                                         !0, 'add'
         12        SEND_VAL_EX                                              'huevos'
         13        SEND_VAL_EX                                              6
         14        DO_FCALL                                      0          
   31    15        INIT_METHOD_CALL                                         !0, 'what_inside_cart'
         16        DO_FCALL                                      0  $7      
         17        ECHO                                                     $7
         18      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FnCn27%3A16%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nCn27
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $cantidad, !1 = $producto, !2 = $cadena
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   17     3        CONCAT                                           ~3      !1, '+-%3E+'
          4        CONCAT                                           ~4      ~3, !0
          5        CONCAT                                           ~5      ~4, '%0D%0A'
          6        ASSIGN_OP                                     8          !2, ~5
   18     7      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FnCn27%3A16%240

Class Carro:
Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nCn27
function name:  add
number of ops:  6
compiled vars:  !0 = $producto, !1 = $cantidad
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        FETCH_OBJ_W                                      $2      'productos'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   10     5      > RETURN                                                   null

End of function add

Function what_inside_cart:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nCn27
function name:  what_inside_cart
number of ops:  10
compiled vars:  !0 = $cadena
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                   !0, ''
   16     1        INIT_FCALL                                               'array_walk'
          2        FETCH_OBJ_W                                      $2      'productos'
          3        SEND_REF                                                 $2
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FnCn27%3A16%240'
          5        BIND_LEXICAL                                             ~3, !0
   18     6        SEND_VAL                                                 ~3
          7        DO_ICALL                                                 
   19     8      > RETURN                                                   !0
   20     9*     > RETURN                                                   null

End of function what_inside_cart

End of class Carro.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.65 ms | 1392 KiB | 15 Q