-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Fix GH-10292 make the default value of the first param of srand() and mt_srand() nullable #10380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Diff LGTM apart from that nit, I don't have any strong target branch preference.
Co-authored-by: Tim Düsterhus <timwolla@googlemail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix causes a BC Break. Currently, if null is passed to mt_srand(), integer 0 is used as the seed value unless in strict type mode. As a result, reproducibility-dependent code is broken.
https://3v4l.org/dNTXu
https://3v4l.org/t5G2B
That said, this seems like an appropriate modification to me personally as well. I did not make this change when proposing the Random extension in order not to include an unnecessary BC Break.
Perhaps the target branch should be master
, don't PHP-8.2
.
Slightly off topic, but I am thinking of proposing to deprecate mt_srand itself in PHP 8.3. This function is useful, but it takes the MT state globally on the PHP VM. This is dangerous in the always-on PHP that has become popular in recent years. I would recommend using random_int if you don't want reproducibility of results, and using Randomizer if reproducibility is required. This change may not be necessary if the above proposal is included in PHP 8.3, just in case. |
I welcome this change! I'd be even happier if
Since PHP 8 series is going to be used for a long time, I think we can and should fix the issue in question independently from the RFC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
The implementation looks good, and only targeting "master" makes sense to me. We should not forget to fix the documentation; probably claiming an UNKNOWN default is the way to go for now, and that is likely also the proper solution for the stub.
@kocsismate see https://wiki.php.net/rfc/deprecations_php_8_3#global_mersenne_twister
I agree. |
Do you mean to update the stub for PHP 8.1 and PHP 8.2? I can take care of it, sure! P.S. Is the upgrading note ok? |
LGTM, but this likely should also have a corresponding NEWS entry. |
Or, hmm. Perhaps something like this: Changed |
I liked the suggestion so I used it in the upgrading guide, while I included something much shorter in the news. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks.
@kocsismate Will you handle whatever is required for the non-master versions? |
Yeah, I'll do it tomorrow! Thanks for the reminder! |
No description provided.