-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch refs/heads/1.10.x into 1.11.x
- Loading branch information
Showing
10 changed files
with
195 additions
and
16 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
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,44 @@ | ||
<?php | ||
|
||
namespace FalsyIsset; | ||
|
||
use function PHPStan\Testing\assertType; | ||
use function PHPStan\Testing\assertVariableCertainty; | ||
use PHPStan\TrinaryLogic; | ||
|
||
function mixedIsset(mixed $m): void | ||
{ | ||
if (isset($m)) { | ||
assertType("mixed~null", $m); | ||
} else { | ||
assertType("null", $m); | ||
} | ||
} | ||
|
||
function stdclassIsset(?\stdClass $m): void | ||
{ | ||
if (isset($m)) { | ||
assertType("stdClass", $m); | ||
} else { | ||
assertType("null", $m); | ||
} | ||
} | ||
|
||
function nullableVariable(?string $a): void | ||
{ | ||
if (isset($a)) { | ||
assertType("string", $a); | ||
} else { | ||
assertType("null", $a); | ||
} | ||
} | ||
|
||
function nullableUnionVariable(null|string|int $a): void | ||
{ | ||
if (isset($a)) { | ||
assertType("int|string", $a); | ||
} else { | ||
assertType("null", $a); | ||
} | ||
} | ||
|
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,30 @@ | ||
<?php | ||
|
||
namespace Bug8659; | ||
|
||
function acceptsString(string $input): string | ||
{ | ||
return $input; | ||
} | ||
|
||
function foo1(?string $bar, ?string $baz): string | ||
{ | ||
assert($bar !== null || $baz !== null); | ||
|
||
// In this case, baz cannot be null (because $bar is and assert above makes sure that at least one value is not-null. Yet phpstan fails. | ||
return $bar ?? acceptsString($baz); | ||
} | ||
|
||
|
||
function foo2(?string $bar, ?string $baz): string | ||
{ | ||
assert($bar !== null || $baz !== null); | ||
|
||
// In this case, PHPStan can resolve that $baz must be string and is OK. | ||
return $bar ?? $baz; | ||
} | ||
|
||
function doBar() { | ||
echo foo1(null, 'a'); | ||
echo foo2(null, 'a'); | ||
} |
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,22 @@ | ||
<?php | ||
|
||
namespace Bug9580; | ||
|
||
|
||
function test(): int|string|float|null | ||
{ | ||
return $_GET['value']; | ||
} | ||
|
||
function onlyNull(null $value): void | ||
{ | ||
|
||
} | ||
|
||
function doFoo() { | ||
$value = test(); | ||
if (isset($value)) { | ||
exit; | ||
} | ||
onlyNull($value); | ||
} |
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,57 @@ | ||
<?php // lint >= 7.4 | ||
|
||
namespace Bug8190; | ||
|
||
/** | ||
* @phpstan-type OwnerBackup array{name: string, isTest?: bool} | ||
*/ | ||
class ClassA | ||
{ | ||
/** @var OwnerBackup */ | ||
public array $ownerBackup; | ||
|
||
/** | ||
* @param OwnerBackup|null $ownerBackup | ||
*/ | ||
public function __construct(?array $ownerBackup) | ||
{ | ||
$this->ownerBackup = $ownerBackup ?? [ | ||
'name' => 'Deleted', | ||
]; | ||
} | ||
|
||
|
||
/** | ||
* @param OwnerBackup|null $ownerBackup | ||
*/ | ||
public function setOwnerBackup(?array $ownerBackup): void | ||
{ | ||
$this->ownerBackup = $ownerBackup ?: [ | ||
'name' => 'Deleted', | ||
]; | ||
} | ||
|
||
/** | ||
* @param OwnerBackup|null $ownerBackup | ||
*/ | ||
public function setOwnerBackupWorksForSomeReason(?array $ownerBackup): void | ||
{ | ||
$this->ownerBackup = $ownerBackup !== null ? $ownerBackup : [ | ||
'name' => 'Deleted', | ||
]; | ||
} | ||
|
||
/** | ||
* @param OwnerBackup|null $ownerBackup | ||
*/ | ||
public function setOwnerBackupAlsoWorksForSomeReason(?array $ownerBackup): void | ||
{ | ||
if ($ownerBackup) { | ||
$this->ownerBackup = $ownerBackup; | ||
} else { | ||
$this->ownerBackup = [ | ||
'name' => 'Deleted', | ||
]; | ||
} | ||
} | ||
} |