Fix counting *scanf() format string placeholders#5594
Fix counting *scanf() format string placeholders#5594hakre wants to merge 2 commits intophpstan:2.1.xfrom
*scanf() format string placeholders#5594Conversation
57da830 to
5742f2b
Compare
sscanf/fscanf format string placeholderssscanf/fscanf format string placeholders
|
This pull request has been marked as ready for review. |
sscanf/fscanf format string placeholders*scanf() format string placeholders
|
Do you know by chance why https://github.com/phpstan/phpstan-src/actions/runs/25431166468/job/74597885107 keeps failing on my changes? I'd like to better understand @staabm |
we see the same errors on others PRs targeting 2.1.x -> this means these errors are not related to your PR |
04f1759 to
bd2dc56
Compare
8a37d48 to
ddd449b
Compare
Additional by-catch fix of a variable misnomer in 023fa08 ("Fix printf parameters rule", 2017-04-02) spotted during review.
Re-add `@` suppression per review to run CI [1] Intentionally the user handle not added [2] [1]: phpstan#5594 (comment) [2]: phpstan#5594 (comment) Remove `@` suppression and version branching per review The reviewer originally asked to replace the custom error handler with `@` suppression. Now they prefer a plain `try/catch` path, without the error handler and without the `@`. This brings us closer to the very first proposal, but removes the `ValueError`‑converting user handler. (Gegenprobe: if PHP 7 warnings interfere with the test, we'll know quickly.)
|
so finally, this seem to work now. only thing missing is a test for the actual problem, you are trying to solve, namely https://phpstan.org/r/f44a6c55-b410-4aae-b174-17b093e62cb0 please add a rule test showing that the error
no longer appears |
|
Yes, I'll add a rule test for that. I can either extend the existing fixture file we already touched in this PR (which seems simplest) or create a new |
|
please add a isolated test-case with your bug number, like we already have similar to e.g. |
|
Pushed — let's see what the test suite says. |
Update PrintfHelper.php to make
public function getScanfPlaceholdersCount(string $format): ?int`
return the sscanf() vetted number of placeholders that return/assign
conversions.
Addresses long-standing regressions reported originally in
[phpstan-10260].
References:
- [phpstan-10260]
- phpstan/phpstan#10260 (comment)
- [phpstan-src-5591]
- [phpstan-14567]
- https://3v4l.org/WR85Q
[phpstan-10260]: phpstan/phpstan#10260
[phpstan-src-5591]: phpstan#5591
[phpstan-14567]: phpstan/phpstan#14567
|
Test suite is happy. Let me know if anything else is needed. |
|
Thanks for the quick review. I'm afk for a bit – feel free to nudge if I miss anything. |
Update PrintfHelper.php:
Make
public function getScanfPlaceholdersCount(string $format): ?intreturning the sscanf() vetted number of placeholders that give/return/assign conversions.refs:
sscanf/fscanfformat string at NUL byte before counting placeholders #5591