mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Merge pull request #10231 from MidnightDesign/sprintf-stringable-values
Allow stringable objects in `sprintf()` values
This commit is contained in:
commit
db07b05156
@ -1292,7 +1292,7 @@ function preg_quote(string $str, ?string $delimiter = null) : string {}
|
||||
/**
|
||||
* @psalm-pure
|
||||
*
|
||||
* @param string|int|float $values
|
||||
* @param string|stringable-object|int|float $values
|
||||
* @return (PHP_MAJOR_VERSION is 8 ? string : string|false)
|
||||
* @psalm-ignore-falsable-return
|
||||
*
|
||||
|
@ -125,6 +125,18 @@ class CoreStubsTest extends TestCase
|
||||
'$a===' => 'string',
|
||||
],
|
||||
];
|
||||
yield 'sprintf accepts Stringable values' => [
|
||||
'code' => '<?php
|
||||
|
||||
$a = sprintf(
|
||||
"%s",
|
||||
new class implements Stringable { public function __toString(): string { return "hello"; } },
|
||||
);
|
||||
',
|
||||
'assertions' => [],
|
||||
'ignored_issues' => [],
|
||||
'php_version' => '8.0',
|
||||
];
|
||||
yield 'json_encode returns a non-empty-string provided JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE' => [
|
||||
'code' => '<?php
|
||||
$a = json_encode([], JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);
|
||||
|
@ -261,19 +261,6 @@ class ToStringTest extends TestCase
|
||||
fooFoo(new A());',
|
||||
'error_message' => 'InvalidArgument',
|
||||
],
|
||||
'implicitCastWithStrictTypesToEchoOrSprintf' => [
|
||||
'code' => '<?php declare(strict_types=1);
|
||||
class A {
|
||||
public function __toString(): string
|
||||
{
|
||||
return "hello";
|
||||
}
|
||||
}
|
||||
|
||||
echo(new A());
|
||||
sprintf("hello *", new A());',
|
||||
'error_message' => 'ImplicitToStringCast',
|
||||
],
|
||||
'implicitCast' => [
|
||||
'code' => '<?php
|
||||
class A {
|
||||
|
Loading…
Reference in New Issue
Block a user