Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5661ea6
commit 47b013b
Showing
10 changed files
with
140 additions
and
1 deletion.
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
40 changes: 40 additions & 0 deletions
40
docs/running_psalm/issues/UnsupportedPropertyReferenceUsage.md
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,40 @@ | ||
# UnsupportedPropertyReferenceUsage | ||
|
||
Psalm cannot guarantee the soundness of code that uses references to properties. | ||
|
||
### Examples of Uncaught Errors | ||
|
||
* Instance property assigned wrong type: | ||
```php | ||
<?php | ||
class A { | ||
public int $b = 0; | ||
} | ||
$a = new A(); | ||
$b = &$a->b; | ||
$b = ''; // Fatal error | ||
``` | ||
|
||
* Static property assigned wrong type: | ||
```php | ||
<?php | ||
class A { | ||
public static int $b = 0; | ||
} | ||
$b = &A::$b; | ||
$b = ''; // Fatal error | ||
``` | ||
|
||
* Readonly property reassigned: | ||
```php | ||
<?php | ||
class A { | ||
public function __construct( | ||
public readonly int $b, | ||
) { | ||
} | ||
} | ||
$a = new A(0); | ||
$b = &$a->b; | ||
$b = 1; // Fatal error | ||
``` |
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psalm\Issue; | ||
|
||
use Psalm\CodeLocation; | ||
|
||
final class UnsupportedPropertyReferenceUsage extends CodeIssue | ||
{ | ||
public const ERROR_LEVEL = -1; | ||
public const SHORTCODE = 321; | ||
|
||
public function __construct(CodeLocation $code_location) | ||
{ | ||
parent::__construct( | ||
'This reference cannot be analyzed by Psalm.', | ||
$code_location, | ||
); | ||
} | ||
} |
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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psalm\Tests; | ||
|
||
use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait; | ||
|
||
class UnsupportedPropertyReferenceUsage extends TestCase | ||
{ | ||
use InvalidCodeAnalysisTestTrait; | ||
|
||
public function providerInvalidCodeParse(): iterable | ||
{ | ||
return [ | ||
'instance property' => [ | ||
'code' => <<<'PHP' | ||
<?php | ||
class A { | ||
public int $b = 0; | ||
} | ||
$a = new A(); | ||
$b = &$a->b; | ||
$b = ''; // Fatal error | ||
PHP, | ||
'error_message' => 'UnsupportedPropertyReferenceUsage', | ||
], | ||
'static property' => [ | ||
'code' => <<<'PHP' | ||
<?php | ||
class A { | ||
public static int $b = 0; | ||
} | ||
$b = &A::$b; | ||
$b = ''; // Fatal error | ||
PHP, | ||
'error_message' => 'UnsupportedPropertyReferenceUsage', | ||
], | ||
'readonly property' => [ | ||
'code' => <<<'PHP' | ||
<?php | ||
class A { | ||
public function __construct( | ||
public readonly int $b, | ||
) { | ||
} | ||
} | ||
$a = new A(0); | ||
$b = &$a->b; | ||
$b = 1; // Fatal error | ||
PHP, | ||
'error_message' => 'UnsupportedPropertyReferenceUsage', | ||
'error_levels' => [], | ||
'php_version' => '8.1', | ||
], | ||
]; | ||
} | ||
} |
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