Skip to content

Commit a45093f

Browse files
SanderMullerclaude
andauthored
Use rtrim() semantics for chop() on constant strings (#7012)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6294159 commit a45093f

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎src/Type/Php/TrimFunctionDynamicReturnTypeExtension.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function getTypeFromFunctionCall(
7171
if (count($stringConstantStrings) > 0) {
7272
foreach ($stringConstantStrings as $stringConstantString) {
7373
$result[] = new ConstantStringType(
74-
$functionName === 'rtrim'
74+
in_array($functionName, ['rtrim', 'chop'], true)
7575
? rtrim($stringConstantString->getValue(), $trimConstantString->getValue())
7676
: trim($stringConstantString->getValue(), $trimConstantString->getValue()),
7777
true,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug15684;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
function doFoo(): void
8+
{
9+
assertType("' a'", chop(' a ', ' '));
10+
assertType("'yax'", chop('yax', 'y'));
11+
assertType("' a'", rtrim(' a ', ' '));
12+
assertType('true', chop(' a ', ' ') === ' a');
13+
}

0 commit comments

Comments
 (0)