3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Illustrating PHP Function parameters. */ class o { private $v = 0; public function inc() { $this->v++; } public function getV() { return $this->v; } } function testParams(o $obj) { for ($x=0; $x < 10; $x++) { $obj->inc(); } return $obj->getV(); } function testParams2($fp, $text) { $text = "1." . $text . PHP_EOL; fwrite($fp, $text); } // Pass Array by Reference function testParams3(Array &$globArray) { array_push($globArray, 'grape'); } // Globally scoped variables $globArray = ['apple', 'banana', 'peach']; $obj = new o(); $r = fopen("/tmp/resource.txt", "w+"); $text = "This is some text."; // $retVal = testParams($obj); echo $retVal . PHP_EOL; echo $obj->getV() . PHP_EOL; echo PHP_EOL; echo "text before testParams2: \n"; echo "\t$text" . PHP_EOL; testParams2($r, $text); rewind($r); $fileData = fgets($r, 4096); echo "File Data:\n"; echo "\t$fileData"; echo "text After testParams2::\n"; echo "\t$text" . PHP_EOL; echo PHP_EOL; echo "Array Before testParams3:\n"; var_dump($globArray); echo PHP_EOL; testParams3($globArray); echo "Array After testParams3:\n"; var_dump($globArray);
Output for git.master_jit, git.master
Warning: Module "Zend OPcache" is already loaded in Unknown on line 0 Warning: Zend OPcache: module registration failed! in Unknown on line 0 10 10 text before testParams2: This is some text. File Data: 1.This is some text. text After testParams2:: This is some text. Array Before testParams3: array(3) { [0]=> string(5) "apple" [1]=> string(6) "banana" [2]=> string(5) "peach" } Array After testParams3: array(4) { [0]=> string(5) "apple" [1]=> string(6) "banana" [2]=> string(5) "peach" [3]=> string(5) "grape" }

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:
32.89 ms | 407 KiB | 5 Q