3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); class TClass { public function __construct(String $s) {} } $test_values = ['string', null, [1], 1, 3.14, true]; foreach ($test_values as $v) { try { $t = new TClass($v); } catch (TypeError $e) { // Must be catched for null, Int, Float, Array: echo 'OK, catched: ' . $e->getMessage() . PHP_EOL; } } echo PHP_EOL . 'Now the same code with eval():' . PHP_EOL; foreach ($test_values as $v) { try { eval('declare(strict_types=1); $t = new TClass($v);'); } catch (TypeError $e) { // Must be catched for null, Int, Float, Array: echo 'OK, catched: ' . $e->getMessage() . PHP_EOL; } } // BUG: there are NO TypeError for Int, Float, Bool
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.34
OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, null given, called in /in/vPgvb on line 12 OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, array given, called in /in/vPgvb on line 12 OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, int given, called in /in/vPgvb on line 12 OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, float given, called in /in/vPgvb on line 12 OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, bool given, called in /in/vPgvb on line 12 Now the same code with eval(): OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, null given, called in /in/vPgvb(24) : eval()'d code on line 1 OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, array given, called in /in/vPgvb(24) : eval()'d code on line 1 OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, int given, called in /in/vPgvb(24) : eval()'d code on line 1 OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, float given, called in /in/vPgvb(24) : eval()'d code on line 1 OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, bool given, called in /in/vPgvb(24) : eval()'d code on line 1
Output for 7.4.0 - 7.4.33
OK, catched: Argument 1 passed to TClass::__construct() must be of the type string, null given, called in /in/vPgvb on line 12 OK, catched: Argument 1 passed to TClass::__construct() must be of the type string, array given, called in /in/vPgvb on line 12 OK, catched: Argument 1 passed to TClass::__construct() must be of the type string, int given, called in /in/vPgvb on line 12 OK, catched: Argument 1 passed to TClass::__construct() must be of the type string, float given, called in /in/vPgvb on line 12 OK, catched: Argument 1 passed to TClass::__construct() must be of the type string, bool given, called in /in/vPgvb on line 12 Now the same code with eval(): OK, catched: Argument 1 passed to TClass::__construct() must be of the type string, null given, called in /in/vPgvb(24) : eval()'d code on line 1 OK, catched: Argument 1 passed to TClass::__construct() must be of the type string, array given, called in /in/vPgvb(24) : eval()'d code on line 1 OK, catched: Argument 1 passed to TClass::__construct() must be of the type string, int given, called in /in/vPgvb(24) : eval()'d code on line 1 OK, catched: Argument 1 passed to TClass::__construct() must be of the type string, float given, called in /in/vPgvb(24) : eval()'d code on line 1 OK, catched: Argument 1 passed to TClass::__construct() must be of the type string, bool given, called in /in/vPgvb(24) : eval()'d code on line 1
Output for 8.3.0 - 8.3.35, 8.4.1 - 8.4.26, 8.5.0 - 8.5.11
OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, null given, called in /in/vPgvb on line 12 OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, array given, called in /in/vPgvb on line 12 OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, int given, called in /in/vPgvb on line 12 OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, float given, called in /in/vPgvb on line 12 OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, true given, called in /in/vPgvb on line 12 Now the same code with eval(): OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, null given, called in /in/vPgvb(24) : eval()'d code on line 1 OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, array given, called in /in/vPgvb(24) : eval()'d code on line 1 OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, int given, called in /in/vPgvb(24) : eval()'d code on line 1 OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, float given, called in /in/vPgvb(24) : eval()'d code on line 1 OK, catched: TClass::__construct(): Argument #1 ($s) must be of type string, true given, called in /in/vPgvb(24) : eval()'d code on line 1

preferences:
39.08 ms | 1150 KiB | 11 Q