3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Kubus { public function set_sisi($s); public function luas_kubus(); public function volume_kubus(); } interface Balok { public function luas_balok($p, $l); public function volume_balok($t); } class Hitung implements Kubus, Balok{ public $p,$l,$sisi; public function set_sisi($s) { $this->sisi = $s; return $this; } public function luas_kubus() { echo "Luas Kubus = " . $this->sisi * 2 . PHP_EOL; return $this; } public function volume_kubus() { echo "Volume Kubus = " . $this->sisi * 3 . PHP_EOL; return $this; } public function luas_balok($p, $l) { $this->p = $p; $this->l = $l; echo "Luas Balok = " . $p * $l . PHP_EOL; return $this; } public function volume_balok($t) { echo "Volume Balok = " . $this->p * $this->l * $t . PHP_EOL; } } $hitung = new Hitung; echo $hitung->set_sisi(4)->luas_kubus()->volume_kubus()->luas_balok(8,4)->volume_balok(2);
based on A3PYF
Output for 5.0.2 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.24, 7.4.0 - 7.4.12, 8.0.0
Luas Kubus = 8 Volume Kubus = 12 Luas Balok = 32 Volume Balok = 64
Output for 5.0.0 - 5.0.1
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mRE5J on line 21 Luas Kubus = 8PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mRE5J on line 26 Volume Kubus = 12PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mRE5J on line 32 Luas Balok = 32PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/mRE5J on line 36 Volume Balok = 64PHP_EOL
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING in /in/mRE5J on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING in /in/mRE5J on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/mRE5J on line 3
Process exited with code 255.