3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Average{ var $samples; //配列 function Average(){ $this->samples = array(); } //追加 function add($value){ $this->samples[sizeof($this->samples)] = $value; } //配列件数表示 function countValues(){ return sizeof($this->samples); } //最大値 function getMax(){ $max = 0; foreach ($this->samples as $value) { if ($max < $value) { $max = $value; } } return $max; } //平均値 function getAverage(){ if(0 == sizeof($this->samples)){ return 0; } $sum = 0; foreach ($this->samples as $value) { $sum += $value; } return $sum / sizeof($this->samples); } } $avg = new Average; for ($i=1; $i <=10 ; $i++) { $avg->add($i); } echo $avg->getAverage();
Output for 8.0.10 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Fatal error: Uncaught TypeError: sizeof(): Argument #1 ($value) must be of type Countable|array, null given in /in/fXAdW:11 Stack trace: #0 /in/fXAdW(44): Average->add(1) #1 {main} thrown in /in/fXAdW on line 11
Process exited with code 255.
Output for 8.0.0 - 8.0.9
Fatal error: Uncaught TypeError: sizeof(): Argument #1 ($var) must be of type Countable|array, null given in /in/fXAdW:11 Stack trace: #0 /in/fXAdW(44): Average->add(1) #1 {main} thrown in /in/fXAdW on line 11
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Average has a deprecated constructor in /in/fXAdW on line 2 5.5
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.3.32 - 7.3.33
5.5

preferences:
208.53 ms | 402 KiB | 331 Q