Skip to content
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

Difference between string increment typing and reality #10187

Closed
zonuexe opened this issue Nov 25, 2023 · 2 comments
Closed

Difference between string increment typing and reality #10187

zonuexe opened this issue Nov 25, 2023 · 2 comments
Labels
Milestone

Comments

@zonuexe
Copy link
Contributor

zonuexe commented Nov 25, 2023

Bug report

The result of incrementing a string is not necessarily a string.

function inc(string $n): string
{
	$before = $n;
	$after = ++$n;
	assertType('array{string|int, string, string|int}', [$n, $before, $after]));

	return (string)$after; // No warnings expected here
}

inc('10'); // => '11'
inc('a');  // => 'b'

This behavior is consistent between PHP 8.3 and earlier: https://3v4l.org/i4rru

There seems to be a problem with InitializerExprTypeResolver::getPlusType().

Code snippet that reproduces the problem

https://phpstan.org/r/110b3926-f4c5-4f51-b4ab-537fa2be3fb6

Expected output

No errors.

Did PHPStan help you today? Did it make you happy in any way?

I'm excited to see that PHPStan is working consistently even with PHP 8.3.

@ondrejmirtes
Copy link
Member

Fixed phpstan/phpstan-src#2797

Copy link

github-actions bot commented May 7, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants