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);
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14, 8.5.0
int(3) bool(true) bool(true) int(1) bool(true) bool(false) int(2) bool(false) bool(true) int(0) bool(false) bool(false)
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 8.3.28
/bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28)
Process exited with code 1.

preferences:
64.38 ms | 407 KiB | 5 Q