-
Notifications
You must be signed in to change notification settings - Fork 659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Iterating preg_match_all() matches no longer allowed in pure functions #4128
Labels
Comments
I found these snippets: https://psalm.dev/r/f170f02c7e<?php
/**
* @psalm-pure
*
* @return string[]
*/
function extractUsernames(string $input): array
{
preg_match_all('/@[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}(?!\w)/', $input, $matches);
$usernames = [];
foreach ($matches[0] as $username) {
$usernames[] = ltrim($username, '@');
}
return $usernames;
}
var_dump(extractUsernames('This issue was reported by @colinodell'));
|
Simplified: https://psalm.dev/r/aa99f2c9fc |
I found these snippets: https://psalm.dev/r/aa99f2c9fc<?php
/**
* @psalm-pure
*
* @param mixed $input
*/
function extractUsernames($input): void
{
foreach ($input as $_v) {}
}
|
Yeah, what really needs to happen here is that Psalm understands the type of |
Shouldn't there be a separate issue type, something like |
Yeah, you're right about that too |
colinodell
added a commit
to thephpleague/commonmark
that referenced
this issue
Sep 6, 2020
muglug
added a commit
that referenced
this issue
Sep 7, 2020
danog
pushed a commit
to danog/psalm
that referenced
this issue
Jan 29, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Iterating over
preg_match_all()
matches within a pure function used to be allowed but now it causes anImpureMethodCall
error:Cannot call a possibly-mutating iterator from a pure context
Example: https://psalm.dev/r/f170f02c7e
I would expect this example to be allowed from within a pure function since it matches the definition of a pure function and the value of
$matches
can never be modified outside of that function.The first time I noticed this error was in version 3.15. This error was not raised in 3.14.2.
I believe this might be related to #4064 but I'm not entirely sure.
The text was updated successfully, but these errors were encountered: