Skip to content

[Php70] Skip seeded files and unordered bounds in RandomFunctionRector - #9016

Merged
TomasVotruba merged 1 commit into
mainfrom
random-function-skip-seeded-and-unordered-bounds
Nov 23, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
random-function-skip-seeded-and-unordered-bounds

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

random_int() ignores the srand()/mt_srand() seed and throws ValueError when min > max, while rand() accepts both:

srand(42);
$a = rand(1, 6);      // was turned into random_int(1, 6) - no longer deterministic
rand($min, $max);     // was turned into random_int($min, $max) - throws when $min > $max

The fix:

  • keep rand() when the file calls srand() or mt_srand() - srand -> mt_srand and getrandmax -> mt_getrandmax still apply, as rand() is an alias of mt_rand() since PHP 7.1
  • rename rand($min, $max) only when both bounds resolve to constant int types, swapping them when min > max as before; otherwise skip

The existing fixture was split, as it mixed srand() with rand() and non-constant bounds in one function.

@TomasVotruba
TomasVotruba merged commit 5164ebe into main Nov 23, 2026
51 checks passed
@TomasVotruba
TomasVotruba deleted the random-function-skip-seeded-and-unordered-bounds branch November 23, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant