Skip to content

Commit c957182

Browse files
committed
Fix "Crash: str_increment(): Argument #1 ($string) must be composed only of alphanumeric ASCII characters"
1 parent e9556fb commit c957182

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/Analyser/MutatingScope.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
use PHPStan\Type\VoidType;
140140
use stdClass;
141141
use Throwable;
142+
use ValueError;
142143
use function abs;
143144
use function array_filter;
144145
use function array_key_exists;
@@ -1750,7 +1751,11 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
17501751
&& !is_numeric($varValue)
17511752
&& function_exists('str_increment')
17521753
) {
1753-
$varValue = str_increment($varValue);
1754+
try {
1755+
$varValue = str_increment($varValue);
1756+
} catch (ValueError) {
1757+
return new ErrorType();
1758+
}
17541759
} elseif (!is_bool($varValue)) {
17551760
++$varValue;
17561761
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php // lint < 8.3
2+
3+
namespace bug13481;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
function bug13481() {
8+
$s = 'ab c1';
9+
++$s;
10+
assertType("'ab c2'", $s);
11+
}
12+
13+
function bug13481b() {
14+
$s = '%';
15+
++$s;
16+
assertType("'%'", $s);
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php // lint >= 8.3
2+
3+
namespace bug13481;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
function bug13481() {
8+
$s = 'ab c1';
9+
++$s;
10+
assertType("*ERROR*", $s);
11+
}
12+
13+
function bug13481b() {
14+
$s = '%';
15+
++$s;
16+
assertType("*ERROR*", $s);
17+
}

0 commit comments

Comments
 (0)