Skip to content

Accept null and 0 for microseconds argument in stream_select() #7617

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

Closed
wants to merge 1 commit into from

Conversation

zobo
Copy link
Contributor

@zobo zobo commented Oct 27, 2021

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 INT

However 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)

  1. if it's 0 - a deprecation error emitted
  2. if it's not 0 an exception is thrown

Here should be noted that the first argument $tv_sec acts as a gate-keeper to the php_select argument tv_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.

@zobo
Copy link
Contributor Author

zobo commented Oct 27, 2021

Another argument could be:
If the current $tv_usec default value is 0 (see https://www.php.net/manual/en/function.stream-select.php) how come passing this value in 8.1 produces a deprecation warning...

Copy link
Member

@kelunik kelunik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with delaying the deprecation to a later point in the PHP 8 release line. You'll need to change the PR to target the 8.1 branch, as master is already 8.2.

@zobo zobo force-pushed the fix-stream-select-usec-0 branch from d78ddc1 to 1e105fe Compare October 28, 2021 07:53
@zobo zobo changed the base branch from master to PHP-8.1 October 28, 2021 07:53
@zobo
Copy link
Contributor Author

zobo commented Oct 28, 2021

Rebased onto 8.1. Thanks for considering this.

@nikic nikic closed this in a4ed171 Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants