3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Carro { protected $productos = array (); public function add ( $producto, $cantidad ) { $this->productos[$producto] = $cantidad; } public function what_inside_cart () { $cadena = ""; $callback = function ( $cantidad, $producto ) use ( $cadena ) { echo $cantidad; $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];
Output for 7.1.0
1 Warning: A non-numeric value encountered in /in/r2ibB on line 19 Warning: A non-numeric value encountered in /in/r2ibB on line 19 3 Warning: A non-numeric value encountered in /in/r2ibB on line 19 Warning: A non-numeric value encountered in /in/r2ibB on line 19 6 Warning: A non-numeric value encountered in /in/r2ibB on line 19 Warning: A non-numeric value encountered in /in/r2ibB on line 19
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.0.14
136
Output for 5.2.3 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/r2ibB on line 16
Process exited with code 255.
Output for 5.1.0 - 5.2.2
<br /> <b>Parse error</b>: syntax error, unexpected T_FUNCTION in <b>/in/r2ibB</b> on line <b>16</b><br />
Process exited with code 255.
Output for 5.0.0 - 5.0.5
<br /> <b>Parse error</b>: parse error, unexpected T_FUNCTION in <b>/in/r2ibB</b> on line <b>16</b><br />
Process exited with code 255.
Output for 4.4.2 - 4.4.9
<br /> <b>Parse error</b>: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in <b>/in/r2ibB</b> on line <b>5</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
<br /> <b>Parse error</b>: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in <b>/in/r2ibB</b> on line <b>5</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Parse error</b>: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in <b>/in/r2ibB</b> on line <b>5</b><br />
Process exited with code 255.