Skip to content

Commit

Permalink
strval accepts Stringable
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 9, 2023
1 parent 670d04d commit 3a4cd59
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion resources/functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11807,7 +11807,7 @@
'strtoupper' => ['string', 'str'=>'string'],
'strtr' => ['string', 'str'=>'string', 'from'=>'string', 'to'=>'string'],
'strtr\'1' => ['string', 'str'=>'string', 'replace_pairs'=>'array'],
'strval' => ['string', 'var'=>'scalar|resource|null'],
'strval' => ['string', 'var'=>'__stringAndStringable|int|float|bool|resource|null'],
'substr' => ['__benevolent<string|false>', 'string'=>'string', 'start'=>'int', 'length='=>'int'],
'substr_compare' => ['int<-1, 1>|false', 'main_str'=>'string', 'str'=>'string', 'offset'=>'int', 'length='=>'int', 'case_sensitivity='=>'bool'],
'substr_count' => ['0|positive-int', 'haystack'=>'string', 'needle'=>'string', 'offset='=>'int', 'length='=>'int'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1329,4 +1329,13 @@ public function testFilterInputType(): void
$this->analyse([__DIR__ . '/data/filter-input-type.php'], $errors);
}

public function testBug9283(): void
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Test requires PHP 8.0');
}

$this->analyse([__DIR__ . '/data/bug-9283.php'], []);
}

}
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-9283.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types = 1); // lint >= 8.0

namespace Bug9283;

/**
* @param \Stringable $obj
*/
function test(object $obj): string {
return strval($obj);
}

0 comments on commit 3a4cd59

Please sign in to comment.