Open staabm opened 9 years ago
issue can be reproduced by running the unit tests in https://github.com/nikic/FastRoute/blob/master/test/Dispatcher/MarkBasedTest.php
Isolated repro: https://3v4l.org/bu2jg
Thanks - just out of curiosity as a user, are there advantages of MARK over named captures? https://3v4l.org/gfOnZ
@fredemmott The main advantage is that there's only one "capture". So if you want to determine which of a number of paths a regex has taken, instead of
(?<a>...) | (?<b>...) | (?<c>...) | (?<d>...) | ...
which will create one capturing group for each path, with exactly one of them having a non-empty value (assuming you don't have any subexpressions matching an empty string). With marks, that would be
(*MARK:A)... | (*MARK:B) ... | (*MARK:C) ... | (*MARK:D) ... | ...
and you end up with a single pseudo-capture telling you which path was taken. This avoid creating a huge capture array and you also don't need to scan throw it to find what you want.
Thanks, TIL :)
PCRE Marks are supported by php since 5.6 http://grokbase.com/t/php/php-internals/142wrqvs7p/add-support-for-pcre-marks
see also https://github.com/nikic/FastRoute/pull/22