Skip to content

Commit 72e4e1d

Browse files
authored
Merge pull request #9434 from weirdan/array_pop-is-impure
`array_pop` is impure
2 parents 381a23b + 007ffae commit 72e4e1d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Psalm/Internal/Codebase/Functions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ public function isCallMapFunctionPure(
476476
'date_default_timezone_set', 'assert_options', 'setlocale',
477477
'set_exception_handler', 'set_time_limit', 'putenv', 'spl_autoload_register',
478478
'spl_autoload_unregister', 'microtime', 'array_rand', 'set_include_path',
479+
'array_pop',
479480

480481
// logging
481482
'openlog', 'syslog', 'error_log', 'define_syslog_variables',

tests/PureAnnotationTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,30 @@ function (): void {}
902902
',
903903
'error_message' => 'ImpureFunctionCall',
904904
],
905+
'array_popIsNotMutationFree' => [
906+
'code' => <<<'PHP'
907+
<?php
908+
class Stack
909+
{
910+
/** @var array<string> */
911+
private array $stack = [];
912+
913+
public function push(string $item): void
914+
{
915+
$this->stack[] = $item;
916+
}
917+
918+
/** @psalm-mutation-free */
919+
public function next(): string|null
920+
{
921+
return array_pop($this->stack);
922+
}
923+
}
924+
PHP,
925+
'error_message' => 'ImpureFunctionCall',
926+
'ignored_issues' => [],
927+
'php_version' => '8.0',
928+
],
905929
];
906930
}
907931
}

0 commit comments

Comments
 (0)