-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Accept null for microseconds argument in stream_select() #6879
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
The deprecation of passing null is thrown otherwise. If the timeout is calculated conditionally before calling stream_select(), passing to avoid the deprecation seems unreasonable, example: https://github.com/amphp/amp/blob/7d4bbc6e0b47c6bb39b6cce1a4b5942e0c5125fb/lib/Loop/NativeDriver.php#L286
I think this makes sense. If $sec is nullable, then $usec should be too. cc @kocsismate |
@@ -788,6 +789,11 @@ PHP_FUNCTION(stream_select) | |||
|
|||
PHP_SAFE_MAX_FD(max_fd, max_set_count); | |||
|
|||
if (secnull && !usecnull) { |
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.
Maybe we should allow || usec == 0
here, so those tests wouldn't have broken? After all, this was documented as the default.
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.
I thought about that, too, but there's no reason to pass 0
in these tests.
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.
I'm mainly concerned about people who have defined a wrapper around this function that uses $usec = 0
as the default value, because that's the default we used to document. They would now get an exception.
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.
Should we deprecate passing 0
or just allow it?
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.
Downgraded passing 0
to a deprecation message.
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.
I think this makes sense. If $sec is nullable, then $usec should be too.
+1
I understand this has as been in the 8.1 tree a while, but I just stumbled on it in the exact same spot as the mentioned issue. Writing code that fully satisfies PHP <= 8.0 and >= 8.1 is.. well.. impossible and results in ugly patches as this https://github.com/sabre-io/event/pull/88/files Since <= 8.0 did not allow $usec to be NULL there is no way to avoid a deprecation notice - or write version specific split code. I would suggest to allow $usec to be either NULL or 0. |
I'd be okay with dropping the deprecation. Don't see much value in it. |
Can I help in any way? |
@zobo I haven't seen any issue with passing |
PHP 8.0 and before define the 7.4.13: 8.0.12: code <?php
declare(strict_types=1);
$r = $w = $e = [STDIN];
stream_select($r, $w, $e, null, null); |
Strict types have been the missing piece, we're not using them at @amphp, so we didn't see any Regarding the usefulness of the deprecation:
Returns immediately.
Blocks forever. Given this difference, the deprecation still seems relevant to me. |
Yes. But thats controlled by the 4th parameter $sec. Deprecation notice is about the 5th. |
I have created a PR that makes the proposed change, removing the deprecation warning. |
The deprecation of passing null is thrown otherwise.
If the timeout is calculated conditionally before calling stream_select(), passing 0 to avoid the deprecation seems unreasonable, example:
https://github.com/amphp/amp/blob/7d4bbc6e0b47c6bb39b6cce1a4b5942e0c5125fb/lib/Loop/NativeDriver.php#L286