3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test_type(mixed $value, string $type) { if (in_array(($actual = gettype($value)), ['string', 'integer', 'NULL'])) { if (str_contains($type, '?') && $actual === 'NULL') return true; return $actual === $type; } return in_array(true, array_map(fn(string $x) => $value instanceof $x, explode('|', $type))); } echo (int) test_type(null, "int"); echo (int) test_type(null, "?int"); echo (int) test_type("hello, world", "bool"); echo (int) test_type(new DateTime, "DateTimeInterface"); echo (int) test_type(new DateTime, "null|int|DateTime|DateTimeImmutable");

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
171.32 ms | 1599 KiB | 17 Q