3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { private $x; private $y; public function __construct() { $this->x = 10; $this->y = function (){ return $this->getToutesLesCommandes();}; } public function getY($k) { return $this->$k; } public function getToutesLesCommandes() { //sleep(5); echo "Et 5 tres longues secondes plus tard..."; return array('commande1' => 123456, 'commande2' => 456789); } } $t = new Test(); //var_dump($t); var_dump($t->getY()); var_dump($t->getY());
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught ArgumentCountError: Too few arguments to function Test::getY(), 0 passed in /in/iZQF5 on line 30 and exactly 1 expected in /in/iZQF5:14 Stack trace: #0 /in/iZQF5(30): Test->getY() #1 {main} thrown in /in/iZQF5 on line 14
Process exited with code 255.
Output for 7.0.0 - 7.0.33
Warning: Missing argument 1 for Test::getY(), called in /in/iZQF5 on line 30 and defined in /in/iZQF5 on line 14 Notice: Undefined variable: k in /in/iZQF5 on line 16 Fatal error: Uncaught Error: Cannot access empty property in /in/iZQF5:16 Stack trace: #0 /in/iZQF5(30): Test->getY() #1 {main} thrown in /in/iZQF5 on line 16
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Warning: Missing argument 1 for Test::getY(), called in /in/iZQF5 on line 30 and defined in /in/iZQF5 on line 14 Notice: Undefined variable: k in /in/iZQF5 on line 16 Fatal error: Cannot access empty property in /in/iZQF5 on line 16
Process exited with code 255.

preferences:
233.67 ms | 402 KiB | 326 Q