-
Notifications
You must be signed in to change notification settings - Fork 514
Bleeding edge: stricter ++/-- operator check #3255
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace InvalidIncDecMixed; | ||
|
||
/** | ||
* @template T | ||
* @param T $a | ||
*/ | ||
function genericMixed(mixed $a): void | ||
{ | ||
$b = $a; | ||
var_dump(++$b); | ||
$b = $a; | ||
var_dump($b++); | ||
$b = $a; | ||
var_dump(--$b); | ||
$b = $a; | ||
var_dump($b--); | ||
} | ||
|
||
function explicitMixed(mixed $a): void | ||
{ | ||
$b = $a; | ||
var_dump(++$b); | ||
$b = $a; | ||
var_dump($b++); | ||
$b = $a; | ||
var_dump(--$b); | ||
$b = $a; | ||
var_dump($b--); | ||
} | ||
|
||
function implicitMixed($a): void | ||
{ | ||
$b = $a; | ||
var_dump(++$b); | ||
$b = $a; | ||
var_dump($b++); | ||
$b = $a; | ||
var_dump(--$b); | ||
$b = $a; | ||
var_dump($b--); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace InvalidIncDecUnion; | ||
|
||
/** | ||
* @param __benevolent<scalar|null|array|object> $benevolentUnion | ||
* @param string|int|float|bool|null $okUnion | ||
* @param scalar|null|array|object $union | ||
* @param __benevolent<array|object> $badBenevolentUnion | ||
*/ | ||
function foo($benevolentUnion, $okUnion, $union, $badBenevolentUnion): void | ||
{ | ||
$a = $benevolentUnion; | ||
$a++; | ||
$a = $benevolentUnion; | ||
--$a; | ||
|
||
$a = $okUnion; | ||
$a++; | ||
$a = $okUnion; | ||
--$a; | ||
|
||
$a = $union; | ||
$a++; | ||
$a = $union; | ||
--$a; | ||
|
||
$a = $badBenevolentUnion; | ||
$a++; | ||
$a = $badBenevolentUnion; | ||
--$a; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
namespace InvalidIncDec; | ||
|
||
function ($a, int $i, ?float $j, string $str, \stdClass $std) { | ||
function ($a, int $i, ?float $j, string $str, \stdClass $std, \SimpleXMLElement $simpleXMLElement) { | ||
$a++; | ||
|
||
$b = [1]; | ||
|
@@ -15,4 +15,41 @@ function ($a, int $i, ?float $j, string $str, \stdClass $std) { | |
$j++; | ||
$str++; | ||
$std++; | ||
$classWithToString = new ClassWithToString(); | ||
$classWithToString++; | ||
$classWithToString = new ClassWithToString(); | ||
--$classWithToString; | ||
$arr = []; | ||
$arr++; | ||
$arr = []; | ||
--$arr; | ||
|
||
if (($f = fopen('php://stdin', 'r')) !== false) { | ||
$f++; | ||
} | ||
|
||
if (($f = fopen('php://stdin', 'r')) !== false) { | ||
--$f; | ||
} | ||
|
||
$bool = true; | ||
$bool++; | ||
$bool = false; | ||
--$bool; | ||
$null = null; | ||
$null++; | ||
$null = null; | ||
--$null; | ||
$a = $simpleXMLElement; | ||
$a++; | ||
$a = $simpleXMLElement; | ||
--$a; | ||
Comment on lines
+43
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was allowed by the previous version of the rule as well (due to |
||
}; | ||
|
||
class ClassWithToString | ||
{ | ||
public function __toString(): string | ||
{ | ||
return 'foo'; | ||
} | ||
} |
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.
Bug:This does work in PHP 7: https://3v4l.org/oXvs8There 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.
It actually works even without
__toString()
, but I'm not sure whether it can be used for anything useful with custom classes: https://3v4l.org/uXLrP I'd prefer to keep it disabled even for PHP 7 unless there is a use-case for it.