-
Notifications
You must be signed in to change notification settings - Fork 523
Fix forgetting static property access after impure call #3950
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1099690
Fix forgetting static property access after impure call
staabm a128206
added regression test
staabm 2a79d7b
Added regression test
staabm 247db4c
Fix forgetting expressions on function calls / closure invoke
staabm b5cf7d3
Update NodeScopeResolver.php
staabm d17e41f
Update MutatingScope.php
staabm 5725c3a
Update NodeScopeResolver.php
staabm ddbd27f
fix name resolving
staabm 1b17eaf
Update MutatingScope.php
staabm 36dc4a4
Added regression test
staabm 54cf6eb
Added regression test
staabm 2327cc0
Added regression test
staabm 8107134
Update ReturnTypeRuleTest.php
staabm f090339
Update NodeScopeResolver.php
staabm 733d883
cleanup
staabm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,27 @@ | ||
<?php | ||
|
||
namespace Bug3747; | ||
|
||
class X { | ||
|
||
/** @var array<string,string> $x */ | ||
private static array $x; | ||
|
||
public function y(): void { | ||
|
||
self::$x = []; | ||
|
||
$this->z(); | ||
|
||
echo self::$x['foo']; | ||
|
||
} | ||
|
||
private function z(): void { | ||
self::$x['foo'] = 'bar'; | ||
} | ||
|
||
} | ||
|
||
$x = new X(); | ||
$x->y(); |
This file contains hidden or 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 hidden or 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 hidden or 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,21 @@ | ||
<?php | ||
|
||
namespace Bug11019; | ||
|
||
class HelloWorld | ||
{ | ||
public static int $a; | ||
|
||
public function reset(): void | ||
{ | ||
static::$a = rand(1,10); | ||
} | ||
|
||
public function sayHello(): void | ||
{ | ||
$this->reset(); | ||
assert(static::$a === 1); | ||
$this->reset(); | ||
assert(static::$a === 1); | ||
} | ||
} |
This file contains hidden or 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,25 @@ | ||
<?php | ||
|
||
namespace Bug4864; | ||
|
||
class Example | ||
{ | ||
/** @var mixed */ | ||
private $value; | ||
private bool $isHandled; | ||
|
||
public function fetchValue(callable $f): void | ||
{ | ||
$this->isHandled = false; | ||
$this->value = null; | ||
|
||
(function () { | ||
$this->isHandled = true; | ||
$this->value = 'value'; | ||
})(); | ||
|
||
if ($this->isHandled) { | ||
$f($this->value); | ||
} | ||
} | ||
} |
This file contains hidden or 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,32 @@ | ||
<?php | ||
|
||
namespace Bug8926; | ||
|
||
class Foo { | ||
private bool $test; | ||
|
||
/** @param int[] $arr */ | ||
function success(array $arr) : void { | ||
$test = false; | ||
(function($arr) use(&$test) { | ||
$test = count($arr) == 1; | ||
})($arr); | ||
|
||
if ($test) { | ||
echo "...\n"; | ||
} | ||
} | ||
|
||
/** @param int[] $arr */ | ||
function error(array $arr) : void { | ||
$this->test = false; | ||
(function($arr) { | ||
$this->test = count($arr) == 1; | ||
})($arr); | ||
|
||
|
||
if ($this->test) { | ||
echo "...\n"; | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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,26 @@ | ||
<?php | ||
|
||
namespace Bug4443; | ||
|
||
class HelloWorld | ||
{ | ||
/** @var array<mixed> */ | ||
private static ?array $arr = null; | ||
|
||
private static function setup(): void | ||
{ | ||
self::$arr = null; | ||
} | ||
|
||
/** @return array<mixed> */ | ||
public static function getArray(): array | ||
{ | ||
if (self::$arr === null) { | ||
self::$arr = []; | ||
self::setup(); | ||
} | ||
return self::$arr; | ||
} | ||
} | ||
|
||
HelloWorld::getArray(); |
This file contains hidden or 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,36 @@ | ||
<?php | ||
|
||
namespace Bug8523; | ||
|
||
class HelloWorld | ||
{ | ||
public static ?HelloWorld $instance = null; | ||
|
||
public static function bazz(): void | ||
{ | ||
self::$instance = null; | ||
} | ||
|
||
public function foo(): void | ||
{ | ||
self::$instance = new HelloWorld(); | ||
|
||
self::bazz(); | ||
|
||
self::$instance?->foo(); | ||
} | ||
|
||
public function bar(): void | ||
{ | ||
self::$instance = null; | ||
} | ||
|
||
public function baz(): void | ||
{ | ||
self::$instance = new HelloWorld(); | ||
|
||
$this->bar(); | ||
|
||
self::$instance?->foo(); | ||
} | ||
} |
This file contains hidden or 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,24 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug8523b; | ||
|
||
class HelloWorld | ||
{ | ||
public static ?HelloWorld $instance = null; | ||
|
||
public function save(): void { | ||
self::$instance = new HelloWorld(); | ||
|
||
$callback = static function(): void { | ||
self::$instance = null; | ||
}; | ||
|
||
$callback(); | ||
|
||
var_dump(self::$instance); | ||
|
||
self::$instance?->save(); | ||
} | ||
} | ||
|
||
(new HelloWorld())->save(); | ||
staabm marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last open question: do we want to invalidate 'this' in this case for regular function calls with side-effects?
we only handle Closure at this point right now
see #3950 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scratch that. A function is pretty unlikely to affect
$this
orself