I'm wondering how much of a pain it would be to support type safety with sprintf, i.e. if a string arg is passed to the position for a %u, or a numeric arg is passed to the position for a %s.
sprintf('%u %s', 'test', 1);
https://phpstan.org/r/3e8698758181316ef2d943761e6b184d
The preference (with the example above) would be errors to the effect of :
Argument 2 passed to sprintf on file.php:123 should be an integerArgument 3 passed to sprintf on file.php:123 should be a stringHi, I think that it's valid to pass an integer to %s - it just says "I want to format this as a string". But let's wait for other opinions 馃槉
A different way of phrasing it:
should sprintf with argument 1 of '%u %s' be considered roughly equivalent to this:
function foo(int $a, string $b) : string {
return (string) $a . ' ' . $b; // sidestepping the whole unsigned integer representation issue
}
Closing since the people have spoken with their thumbs 馃槉
Most helpful comment
Hi, I think that it's valid to pass an integer to
%s- it just says "I want to format this as a string". But let's wait for other opinions 馃槉