Skip to content

Commit

Permalink
Allow Stringable in sprintf() values
Browse files Browse the repository at this point in the history
  • Loading branch information
MidnightDesign committed Sep 26, 2023
1 parent 7d8d74d commit 2be674c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions stubs/Php80.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,17 @@ function get_headers(string $url, bool $associative = false, $context = null) :
*/
function pack(string $format, mixed ...$values): string {}

/**
* @psalm-pure
*
* @param string|Stringable|int|float $values
* @return (PHP_MAJOR_VERSION is 8 ? string : string|false)
* @psalm-ignore-falsable-return
*
* @psalm-flow ($format, $values) -> return
*/
function sprintf(string $format, ...$values) {}

final class CurlHandle
{
private function __construct()
Expand Down
12 changes: 12 additions & 0 deletions tests/CoreStubsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ function foo(string $foo): string
'$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);
Expand Down

0 comments on commit 2be674c

Please sign in to comment.