Skip to content

Commit

Permalink
fix: Mark array_shift as having side effects
Browse files Browse the repository at this point in the history
  • Loading branch information
ryium authored and ondrejmirtes committed Jan 8, 2023
1 parent 1403c03 commit fbce69c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/functionMetadata_original.php
Expand Up @@ -36,6 +36,7 @@
'array_replace' => ['hasSideEffects' => false],
'array_replace_recursive' => ['hasSideEffects' => false],
'array_reverse' => ['hasSideEffects' => false],
'array_shift' => ['hasSideEffects' => true],
'array_slice' => ['hasSideEffects' => false],
'array_sum' => ['hasSideEffects' => false],
'array_udiff' => ['hasSideEffects' => false],
Expand Down
1 change: 1 addition & 0 deletions resources/functionMetadata.php
Expand Up @@ -702,6 +702,7 @@
'array_replace_recursive' => ['hasSideEffects' => false],
'array_reverse' => ['hasSideEffects' => false],
'array_search' => ['hasSideEffects' => false],
'array_shift' => ['hasSideEffects' => true],
'array_slice' => ['hasSideEffects' => false],
'array_sum' => ['hasSideEffects' => false],
'array_udiff' => ['hasSideEffects' => false],
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Expand Up @@ -1170,6 +1170,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8635.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8625.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8621.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8084.php');
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/PHPStan/Analyser/data/bug-8084.php
@@ -0,0 +1,16 @@
<?php

namespace Bug8084;

use function array_shift;
use function PHPStan\Testing\assertType;

class Bug8084
{
public function run(array $arr): void
{
/** @var array{a: 0, b?: 1} $arr */
assertType('0', array_shift($arr) ?? throw new \Exception());
assertType('1|null', array_shift($arr));
}
}

0 comments on commit fbce69c

Please sign in to comment.