Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make isset() and null-coalesce (??) operators consistent with each other
* add regression tests for property access with dynamic properties related issues * allow undefined expression for `ObjectWithoutClassType` property fetch * fix test for solved issue * make isset and coalesce consistent * allow overwriting allowedUndefinedExpression because not needed anymore * add regression tests for fixed issues * cs fix * fix levels test for coalesce
- Loading branch information
Showing
10 changed files
with
122 additions
and
45 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 was deleted.
Oops, something went wrong.
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,17 @@ | ||
<?php | ||
|
||
namespace Bug3659; | ||
|
||
class Foo | ||
{ | ||
public function func1(object $obj): void | ||
{ | ||
$this->func2($obj->someProperty ?? null); | ||
} | ||
|
||
public function func2(?string $param): void | ||
{ | ||
echo $param ?? 'test'; | ||
} | ||
} | ||
|
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,14 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug4559; | ||
|
||
class HelloWorld | ||
{ | ||
public function doBar() | ||
{ | ||
$response = json_decode(''); | ||
if (isset($response->error->code)) { | ||
echo $response->error->message ?? ''; | ||
} | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
namespace Bug6026; | ||
|
||
class Foo { | ||
/** | ||
* @param resource $theResource | ||
* @return bool | ||
*/ | ||
public function Process($theResource) : bool | ||
{ | ||
$bucket = \stream_bucket_make_writeable($theResource); | ||
if ( $bucket === null ) | ||
{ | ||
return false; | ||
} | ||
$bucketLen = $bucket->datalen ?? 0; | ||
$bucketLen = isset($bucket->datalen) ? $bucket->datalen : 0; | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug6809; | ||
|
||
trait SomeTrait { | ||
public function __construct() { | ||
$isClassCool = static::$coolClass ?? true; | ||
} | ||
} | ||
|
||
class HelloWorld | ||
{ | ||
use SomeTrait; | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/PHPStan/Rules/Properties/data/dynamic-properties.php
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,19 @@ | ||
<?php | ||
|
||
namespace DynamicProperties; | ||
|
||
class Bar {} | ||
|
||
class Foo { | ||
public function doBar() { | ||
isset($this->dynamicProperty); | ||
empty($this->dynamicProperty); | ||
$this->dynamicProperty ?? 'test'; | ||
|
||
$bar = new Bar(); | ||
isset($bar->dynamicProperty); | ||
empty($bar->dynamicProperty); | ||
$bar->dynamicProperty ?? 'test'; | ||
} | ||
} | ||
|