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");
Output for git.master, git.master_jit
01011

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:
40.69 ms | 978 KiB | 4 Q