Accept null and 0 for microseconds argument in stream_select() #7617
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The previously merged change #6879 makes it impossible to write code that will run on pre PHP8.1 and post PHP8.1 without (at least) a deprecation warning.
Old implementation (https://github.com/php/php-src/blob/PHP-7.4.25/ext/standard/streamsfuncs.c#L764):
$tv_sec
is NULL-able INT$tv_usec
is OPTIONAL INT (can't be null)New implementation (https://github.com/php/php-src/pull/6879/files#diff-4294bfe38876196fc83b34d3b3a8d16919acbc8aaa68ce2fc77859f0ef46b787R757)
$tv_sec
is NULL-able INT$tv_usec
is NULL-able INTHowever the code also adds rules in case
$tv_sec
is NULL and$tv_usec
is not NULL (https://github.com/php/php-src/pull/6879/files#diff-4294bfe38876196fc83b34d3b3a8d16919acbc8aaa68ce2fc77859f0ef46b787R792)Here should be noted that the first argument
$tv_sec
acts as a gate-keeper to thephp_select
argumenttv_p
making the value of$tv_usec
irrelevant in case$tv_sec
is NULL.While the second rule makes sense, as passing any number to
$tv_usec
effectively gets ignored and is logically incorrect, I have a problem with the first rule.In pre PHP8.1 code if you passed both arguments to
stream_select
the the second HAD TO BE an integer.Where in the current implementation - if we are talking the case where
$tv_sec
is NULL - it MUST NOT be, to avoid a deprecation warning.Here is a great example of what I am talking about: https://github.com/sabre-io/event/pull/88/files
This Pull-Request proposes to allow (without warnings)
$tv_usec
to be 0 even if$tv_sec
is NULL as this keeps the behavior of pre and post PHP8.1 the same.