3v4l.org

run code in 300+ PHP versions simultaneously
<?php function autoboxing_error_handler($errno, $errstr, $errfile, $errline, $errcontext) { if (preg_match('/^Argument (\d+) passed to \S+ must be (?:an|an instance of|of the type) (\S+), \S+ given/', $errstr, $match)) { $bt = debug_backtrace(); $value = $bt[1]["args"][$match[1] - 1]; if (strcasecmp($match[2], "array") == 0) { $bt[1]["args"][$match[1] - 1] = array($value); return true; } else if (is_subclass_of($match[2], "Autoboxable")) { $bt[1]["args"][$match[1] - 1] = new $match[2]($value); return true; } } return false; } set_error_handler("autoboxing_error_handler"); interface Autoboxable { public function __construct($value); } class Integer implements Autoboxable { public $value = null; public function __construct($value) { $this->value = (int)$value; } } function foo(Integer $a, array $b) { var_dump($a->value); var_dump($b); } foo("1", 2);
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught TypeError: foo(): Argument #1 ($a) must be of type Integer, string given, called in /in/5lbf0 on line 41 and defined in /in/5lbf0:36 Stack trace: #0 /in/5lbf0(41): foo('1', 2) #1 {main} thrown in /in/5lbf0 on line 36
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:
55.15 ms | 401 KiB | 8 Q