3v4l.org

run code in 300+ PHP versions simultaneously
<?php function strict() { $backtrace = debug_backtrace(0, 2); if (false === $backtrace || count($backtrace) !== 2) { throw new \RuntimeException('strict() must be called from within a function'); } $expectedTypes = func_get_args(); $receivedTypes = array_map('gettype', $backtrace[1]['args']); if (count($expectedTypes) !== count($receivedTypes)) { throw new \InvalidArgumentException('Got ' . count($receivedTypes) . ' arguments, expected ' . count($expectedTypes)); } for ($i = 0; $i < count($expectedTypes); $i++) { if ($expectedTypes[$i] !== $receivedTypes[$i]) { throw new \InvalidArgumentException('Expected argument ' . ($i + 1) . ' to be of type ' . $expectedTypes[$i] . ', received ' . $receivedTypes[$i]); } } } function myargs($a, $b) { strict('string', 'integer'); echo 'Hello'.PHP_EOL; } myargs('hello', 4); myargs(4, 'oof');
Output for git.master, git.master_jit, rfc.property-hooks
Hello Fatal error: Uncaught InvalidArgumentException: Expected argument 1 to be of type string, received integer in /in/GHGNf:20 Stack trace: #0 /in/GHGNf(27): strict('string', 'integer') #1 /in/GHGNf(33): myargs(4, 'oof') #2 {main} thrown in /in/GHGNf on line 20
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:
53.57 ms | 401 KiB | 8 Q