3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface PatternInterface { function match($value); } class LiteralPattern implements PatternInterface { private $value; public function match($value) { return $value === $this->value; } } class DynamicPattern implements PatternInterface { private $name; private $value; public function match($value, &$matches) { return (bool) preg_match($this->getExpression(), $value, $matches); // i can has $matches? } public function getExpression() { return sprintf('/^(?<%s>%s)$/', $this->name, $this->value); } }

preferences:
40.01 ms | 402 KiB | 5 Q