3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Based { private array $arr = ["zero", "one", "two", "three", "four", "five"]; public function removeElementFromArr (int $index): void { array_splice($this->arr, $index, 1); if ($index === 0) { throw new Exception("Cannot remove the first element of an array, reason: https://www.youtube.com/watch?v=bvlSQz7cBr0"); } } public function getArr (): array { return $this->arr; } public function setArr (array $newArr) { $this->arr = $newArr; } } $obj = new Based(); var_dump($obj->getArr()); $obj->removeElementFromArr(3); var_dump($obj->getArr()); $obj->removeElementFromArr(0);
Output for git.master_jit, git.master, rfc.property-hooks
array(6) { [0]=> string(4) "zero" [1]=> string(3) "one" [2]=> string(3) "two" [3]=> string(5) "three" [4]=> string(4) "four" [5]=> string(4) "five" } array(5) { [0]=> string(4) "zero" [1]=> string(3) "one" [2]=> string(3) "two" [3]=> string(4) "four" [4]=> string(4) "five" } Fatal error: Uncaught Exception: Cannot remove the first element of an array, reason: https://www.youtube.com/watch?v=bvlSQz7cBr0 in /in/44QFC:10 Stack trace: #0 /in/44QFC(27): Based->removeElementFromArr(0) #1 {main} thrown in /in/44QFC on line 10
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:
51.12 ms | 406 KiB | 5 Q