Skip to content

Add rules for operand in pre/post-inc/decrement #26

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

Merged
merged 1 commit into from
Jun 18, 2018

Conversation

Majkl578
Copy link
Contributor

@Majkl578 Majkl578 commented Jun 18, 2018

Type check for int/float in:

  • $foo++
  • $foo--
  • ++$foo
  • --$foo

Note that PHP allows wide range of scary and inconsistent magic in these operators which I do not want to implement; some examples:

php > $x = false;
php > $x++;
php > var_dump($x);
bool(false)
php > $x = 'xx';
php > $x++;
php > var_dump($x);
string(2) "xy"
php > $x--;
php > var_dump($x);
string(2) "xy"
php > $x = '?';
php > $x++;
php > var_dump($x);
string(1) "?"
php > $x = 'x2';
php > $x++;
php > var_dump($x);
string(2) "x3"
php > $x = 'x7';
php > $x++;
php > $x++;
php > $x++;
php > var_dump($x);
string(2) "y0"
php > $x = 'zz';
php > $x++;
php > var_dump($x);
string(3) "aaa"
php > $x = ';z9';
php > $x++;
php > $x++;
php > $x++;
php > var_dump($x);
string(3) ";a2"

@ondrejmirtes
Copy link
Member

Thanks! 👍

@ondrejmirtes ondrejmirtes merged commit 586314f into phpstan:master Jun 18, 2018
@Majkl578 Majkl578 deleted the pre-post-inc-dec branch June 19, 2018 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants