-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support
#
comments in regex with x
modifier
- Loading branch information
Showing
2 changed files
with
45 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php // lint >= 7.4 | ||
|
||
namespace Bug12242; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
function foo(string $str): void | ||
{ | ||
$regexp = '/ | ||
# ( | ||
([\d,]*) | ||
# ) | ||
/x'; | ||
if (preg_match($regexp, $str, $match)) { | ||
assertType('array{string, string}', $match); | ||
} | ||
} | ||
|
||
function bar(string $str): void | ||
{ | ||
$regexp = '/^ | ||
(\w+) # column type [1] | ||
[\(] # ( | ||
?([\d,]*) # size or size, precision [2] | ||
[\)] # ) | ||
?\s* # whitespace | ||
(\w*) # extra description (UNSIGNED, CHARACTER SET, ...) [3] | ||
$/x'; | ||
if (preg_match($regexp, $str, $matches)) { | ||
assertType('array{string, non-empty-string, string, string}', $matches); | ||
} | ||
} |