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 git.master, git.master_jit
int(3) bool(true) bool(true) int(1) bool(true) bool(false) int(2) bool(false) bool(true) int(0) bool(false) bool(false)

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:
34.98 ms | 405 KiB | 5 Q