-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make assigning property via reference impure
- Loading branch information
Showing
4 changed files
with
91 additions
and
2 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
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,63 @@ | ||
<?php declare(strict_types = 1); // lint >= 7.4 | ||
|
||
namespace ImpureAssignRef; | ||
|
||
class HelloWorld | ||
{ | ||
public int $value = 0; | ||
/** @var array<int, int> */ | ||
public array $arr = []; | ||
/** @var array<int, \stdClass> */ | ||
public array $objectArr = []; | ||
public static int $staticValue = 0; | ||
/** @var array<int, int> */ | ||
public static array $staticArr = []; | ||
|
||
private function bar1(): void | ||
{ | ||
$value = &$this->value; | ||
$value = 1; | ||
} | ||
|
||
private function bar2(): void | ||
{ | ||
$value = &$this->arr[0]; | ||
$value = 1; | ||
} | ||
|
||
private function bar3(): void | ||
{ | ||
$value = &self::$staticValue; | ||
$value = 1; | ||
} | ||
|
||
private function bar4(): void | ||
{ | ||
$value = &self::$staticArr[0]; | ||
$value = 1; | ||
} | ||
|
||
private function bar5(self $other): void | ||
{ | ||
$value = &$other->value; | ||
$value = 1; | ||
} | ||
|
||
/** @phpstan-pure */ | ||
private function bar6(): int | ||
{ | ||
$value = &$this->objectArr[0]->foo; | ||
|
||
return 1; | ||
} | ||
|
||
public function foo(): void | ||
{ | ||
$this->bar1(); | ||
$this->bar2(); | ||
$this->bar3(); | ||
$this->bar4(); | ||
$this->bar5(new self()); | ||
$this->bar6(); | ||
} | ||
} |