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) { return (bool) preg_match($this->getExpression(), $value, $matches); // i can has $matches? } public function getExpression() { return sprintf('/^(?<%s>%s)$/', $this->name, $this->value); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KaB8i
function name:  (null)
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   DECLARE_CLASS                                            'literalpattern'
   19     1        DECLARE_CLASS                                            'dynamicpattern'
   32     2      > RETURN                                                   1

Class PatternInterface:
Function match:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KaB8i
function name:  match
number of ops:  2
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function match

End of class PatternInterface.

Class LiteralPattern:
Function match:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KaB8i
function name:  match
number of ops:  5
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1        FETCH_OBJ_R                                      ~1      'value'
          2        IS_IDENTICAL                                     ~2      !0, ~1
          3      > RETURN                                                   ~2
   15     4*     > RETURN                                                   null

End of function match

End of class LiteralPattern.

Class DynamicPattern:
Function match:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KaB8i
function name:  match
number of ops:  11
compiled vars:  !0 = $value, !1 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        INIT_FCALL                                               'preg_match'
          2        INIT_METHOD_CALL                                         'getExpression'
          3        DO_FCALL                                      0  $2      
          4        SEND_VAR                                                 $2
          5        SEND_VAR                                                 !0
          6        SEND_REF                                                 !1
          7        DO_ICALL                                         $3      
          8        BOOL                                             ~4      $3
          9      > RETURN                                                   ~4
   26    10*     > RETURN                                                   null

End of function match

Function getexpression:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KaB8i
function name:  getExpression
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   INIT_FCALL                                               'sprintf'
          1        SEND_VAL                                                 '%2F%5E%28%3F%3C%25s%3E%25s%29%24%2F'
          2        FETCH_OBJ_R                                      ~0      'name'
          3        SEND_VAL                                                 ~0
          4        FETCH_OBJ_R                                      ~1      'value'
          5        SEND_VAL                                                 ~1
          6        DO_ICALL                                         $2      
          7      > RETURN                                                   $2
   30     8*     > RETURN                                                   null

End of function getexpression

End of class DynamicPattern.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.09 ms | 1400 KiB | 17 Q