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 git.master, git.master_jit, rfc.property-hooks
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.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
23.99 ms | 401 KiB | 8 Q