3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Twig { const TWIG_PREFIX = 1; const SHORT = 2; public static function getMode(string $input): int { $mode = 0; if (str_contains($input, '<twig:')) { $mode |= Twig::TWIG_PREFIX; } if (preg_match_all('/<([A-Z][a-zA-Z0-9_:-]+)([^>]*)>/', $input, $matches, \PREG_SET_ORDER)) { $mode |= Twig::SHORT; } return $mode; } } // Both $input = '<twig:test></twig:test> <Test>test</Test>'; $mode = Twig::getMode($input); var_dump($mode); $hasTwigPrefix = (bool) ($mode & Twig::TWIG_PREFIX); $hasShort = (bool) ($mode & Twig::SHORT); var_dump($hasTwigPrefix); var_dump($hasShort); // Twig $input = '<twig:test></twig:test>'; $mode = Twig::getMode($input); var_dump($mode); $hasTwigPrefix = (bool) ($mode & Twig::TWIG_PREFIX); $hasShort = (bool) ($mode & Twig::SHORT); var_dump($hasTwigPrefix); var_dump($hasShort); // Short $input = '<Test>test</Test>'; $mode = Twig::getMode($input); var_dump($mode); $hasTwigPrefix = (bool) ($mode & Twig::TWIG_PREFIX); $hasShort = (bool) ($mode & Twig::SHORT); var_dump($hasTwigPrefix); var_dump($hasShort); // Nothing $input = '<section>test</section>'; $mode = Twig::getMode($input); var_dump($mode); $hasTwigPrefix = (bool) ($mode & Twig::TWIG_PREFIX); $hasShort = (bool) ($mode & Twig::SHORT); var_dump($hasTwigPrefix); var_dump($hasShort);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.120.0080.01020.64
8.4.110.0180.00318.69
8.4.100.0060.00817.95
8.4.90.0120.00917.98
8.4.80.0140.00719.82
8.4.70.0030.00817.88
8.4.60.0150.00618.04
8.4.50.0380.00818.10
8.4.40.0410.00917.68
8.4.30.0410.00717.68
8.4.20.0380.01117.83
8.4.10.0370.01117.59
8.3.250.0120.00819.09
8.3.240.0040.00716.61
8.3.230.0050.00616.88
8.3.220.0120.00718.74
8.3.210.0050.00216.64
8.3.200.0110.00816.73
8.3.190.0370.00716.75
8.3.180.0390.00716.54
8.3.170.0410.00916.43
8.3.160.0390.01018.25
8.3.150.0280.01217.09
8.3.140.0340.00716.69
8.3.130.0350.00816.95
8.3.120.0380.00716.73
8.3.110.0330.00416.75
8.3.100.0400.00716.77
8.3.90.0420.00516.77
8.3.80.0390.00916.83
8.3.70.0390.01116.79
8.3.60.0430.00816.91
8.3.50.0350.01416.86
8.3.40.0380.00917.70
8.3.30.0210.01217.82
8.3.20.0330.00817.70
8.3.10.0290.00617.82
8.3.00.0120.00817.70
8.2.290.0120.00518.86
8.2.280.0350.00816.70
8.2.270.0330.00616.74
8.2.260.0290.01016.63
8.2.250.0310.00916.73
8.2.240.0300.00916.70
8.2.230.0340.00516.45
8.2.220.0330.00916.80
8.2.210.0340.00516.54
8.2.200.0330.00916.49
8.2.190.0200.01216.55
8.2.180.0290.01016.78
8.2.170.0260.00718.12
8.2.160.0120.00617.86
8.2.150.0320.01017.70
8.2.140.0320.00517.82
8.2.130.0320.01117.74
8.2.120.0330.01017.86
8.2.110.0330.00917.83
8.2.100.0350.00717.52
8.2.90.0320.00917.79
8.2.80.0380.00617.57
8.2.70.0330.00917.66
8.2.60.0360.00817.70
8.2.50.0380.00717.71
8.2.40.0280.00717.58
8.2.30.0370.00817.75
8.2.20.0300.00917.76
8.2.10.0360.00817.62
8.2.00.0320.00717.64

preferences:
26.84 ms | 403 KiB | 5 Q