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 = ""; $callback = function ( $producto, $cantidad ) use ( $cadena ) { $cadena += $producto . "\r\n"; }; array_walk ( $this->productos, $callback ); 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->what_inside_cart (); //echo $mi_carro->productos[0];
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/j3r71
function name:  (null)
number of ops:  19
compiled vars:  !0 = $mi_carro
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   NEW                                              $1      'Carro'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   29     3        INIT_METHOD_CALL                                         !0, 'add'
          4        SEND_VAL_EX                                              'mantequilla'
          5        SEND_VAL_EX                                              1
          6        DO_FCALL                                      0          
   30     7        INIT_METHOD_CALL                                         !0, 'add'
          8        SEND_VAL_EX                                              'leche'
          9        SEND_VAL_EX                                              3
         10        DO_FCALL                                      0          
   31    11        INIT_METHOD_CALL                                         !0, 'add'
         12        SEND_VAL_EX                                              'huevos'
         13        SEND_VAL_EX                                              6
         14        DO_FCALL                                      0          
   33    15        INIT_METHOD_CALL                                         !0, 'what_inside_cart'
         16        DO_FCALL                                      0  $7      
         17        ECHO                                                     $7
   34    18      > RETURN                                                   1

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

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

Class Carro:
Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/j3r71
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/j3r71
function name:  what_inside_cart
number of ops:  11
compiled vars:  !0 = $cadena, !1 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                   !0, ''
   16     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fj3r71%3A16%240'
          2        BIND_LEXICAL                                             ~3, !0
          3        ASSIGN                                                   !1, ~3
   21     4        INIT_FCALL                                               'array_walk'
          5        FETCH_OBJ_W                                      $5      'productos'
          6        SEND_REF                                                 $5
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                                 
   22     9      > RETURN                                                   !0
   23    10*     > RETURN                                                   null

End of function what_inside_cart

End of class Carro.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.81 ms | 1392 KiB | 15 Q