Skip to content
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

array_pop is impure #9434

Merged
merged 1 commit into from Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Psalm/Internal/Codebase/Functions.php
Expand Up @@ -476,6 +476,7 @@ public function isCallMapFunctionPure(
'date_default_timezone_set', 'assert_options', 'setlocale',
'set_exception_handler', 'set_time_limit', 'putenv', 'spl_autoload_register',
'spl_autoload_unregister', 'microtime', 'array_rand', 'set_include_path',
'array_pop',

// logging
'openlog', 'syslog', 'error_log', 'define_syslog_variables',
Expand Down
24 changes: 24 additions & 0 deletions tests/PureAnnotationTest.php
Expand Up @@ -902,6 +902,30 @@ function (): void {}
',
'error_message' => 'ImpureFunctionCall',
],
'array_popIsNotMutationFree' => [
'code' => <<<'PHP'
<?php
class Stack
{
/** @var array<string> */
private array $stack = [];

public function push(string $item): void
{
$this->stack[] = $item;
}

/** @psalm-mutation-free */
public function next(): string|null
{
return array_pop($this->stack);
}
}
PHP,
'error_message' => 'ImpureFunctionCall',
'ignored_issues' => [],
'php_version' => '8.0',
],
];
}
}