-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not invalidate types passed by value
- Loading branch information
1 parent
52eb6f8
commit 0b8dca7
Showing
4 changed files
with
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,6 +148,7 @@ | |
use PHPStan\Type\NeverType; | ||
use PHPStan\Type\NullType; | ||
use PHPStan\Type\ObjectType; | ||
use PHPStan\Type\ResourceType; | ||
use PHPStan\Type\StaticType; | ||
use PHPStan\Type\StaticTypeFactory; | ||
use PHPStan\Type\StringType; | ||
|
@@ -2010,6 +2011,15 @@ static function (): void { | |
->invalidateExpression(new FuncCall(new Name\FullyQualified('json_last_error_msg'), [])); | ||
} | ||
|
||
if ( | ||
$functionReflection !== null | ||
&& $functionReflection->getName() === 'file_put_contents' | ||
&& count($expr->getArgs()) > 0 | ||
) { | ||
$scope = $scope->invalidateExpression(new FuncCall(new Name('file_get_contents'), [$expr->getArgs()[0]])) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ondrejmirtes
Author
Member
|
||
->invalidateExpression(new FuncCall(new Name\FullyQualified('file_get_contents'), [$expr->getArgs()[0]])); | ||
} | ||
|
||
if ( | ||
$functionReflection !== null | ||
&& in_array($functionReflection->getName(), ['array_pop', 'array_shift'], true) | ||
|
@@ -3600,7 +3610,10 @@ private function processArgs( | |
$scope = $scope->invalidateExpression($argValue); | ||
} | ||
} elseif ($calleeReflection !== null && $calleeReflection->hasSideEffects()->yes()) { | ||
$scope = $scope->invalidateExpression($arg->value, true); | ||
$argType = $scope->getType($arg->value); | ||
if (!$argType->isObject()->no() || !(new ResourceType())->isSuperTypeOf($argType)->no()) { | ||
$scope = $scope->invalidateExpression($arg->value, true); | ||
} | ||
} | ||
} | ||
|
||
|
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,26 @@ | ||
<?php | ||
|
||
namespace Discussion9972; | ||
|
||
use PHPStan\TrinaryLogic; | ||
use function PHPStan\Testing\assertVariableCertainty; | ||
|
||
class HelloWorld | ||
{ | ||
public function f1(bool $myBool): void | ||
{ | ||
if ($myBool) { | ||
$myObject = new DateTime(); | ||
} | ||
|
||
$this->helper($myBool); | ||
|
||
if ($myBool) { | ||
assertVariableCertainty(TrinaryLogic::createYes(), $myObject); | ||
} | ||
} | ||
|
||
protected function helper(bool $input): void | ||
{ | ||
} | ||
} |
is this invalidation tested somewhere?