Add Polyfill for Time\Duration class - #642
Conversation
|
I suggest waiting for the official PHP implementation (also waiting for the actual approval of the RFC even though the result of the vote seems clear). This will allow us to also copy the upstream phpt testcases and to run them with our polyfill (we alreeady do that for the IO Poll polyfill). |
47be87b to
16ed7cf
Compare
|
Added the latest version of the tests from php/php-src#23073 The following adaptation are applied: The pipe operator used in the helper function is backported to a version compatible with older version of PHP (see helper.inc ) The Test that validated that ReflectionException: Class Time\Duration is an internal class marked as final that cannot be instantiated without invoking its constructorA polyfill can never satisfy this test by definition. |
|
Pushed a commit on top: I ran the php-src phpt files (php/php-src#23073) unmodified against the polyfill, and fixed what they don't cover:
The range and the sign of zero durations are now enforced in Tests: the phpt files are byte-identical to Also added the |
|
Followed up on the 32 bit side, where
Since no CI job runs on 32 bit, I checked it with a copy of the stub where Last commit is unrelated: PHP 8.6 doesn't provide the CI is now at parity with |
nicolas-grekas
left a comment
There was a problem hiding this comment.
We're going to need a symfony/polyfill-time subtree-split @fabpot 🙏
I just adjusted helper.inc upstream to not use PFA / Pipe. I thought it was nice to leverage the new PHP 8.6 functionality there, but if it causes troubles, then it's not worth it. There is also a |
|
And as a heads up: You'll also need to adjust the polling API polyfill, since php/php-src#23092 will be merged shortly after merging Time\Duration. Both will be in Beta 1. |
|
@TimWolla thanks, both taken care of.
About The polyfill declares Noted for php/php-src#23092, thanks for the heads up: |
998a80a to
a976c45
Compare
|
Thank you @nyamsprod. |
This PR was squashed before being merged into the 1.x branch. Discussion ---------- [IoPoll] Take Time\Duration in Context::wait() | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT Depends on #642, on top of which this branch sits — only the last commit belongs here. php/php-src#23092 is merged and ships in 8.6 Beta 1, alongside `Time\Duration`. It replaces the `$timeoutSeconds`/`$timeoutMicroseconds` arguments of `Io\Poll\Context::wait()` by a single `?Time\Duration $timeout`: ```php -public function wait(?int $timeoutSeconds = null, int $timeoutMicroseconds = 0, ?int $maxEvents = null): array +public function wait(?\Time\Duration $timeout = null, ?int $maxEvents = null): array ``` The vendored phpt files get exactly the edits php-src made in that commit: `wait(0)` becomes `wait(Time\Duration::fromSeconds(0))` and `wait(0, 100000)` becomes `wait(Time\Duration::fromMicroseconds(100000))`. Every file that was a byte-identical copy of `ext/standard/tests/poll/` still is; the three that already differed (`poll.inc`, `poll_stream_sock_rw_close.phpt`, `poll_stream_sock_rw_multi_level.phpt`, all stale rather than adapted) keep exactly the differences they had. `symfony/polyfill-time` is deliberately not a dependency: the polyfill never builds a `Duration`, it only reads `->negative`, `->seconds` and `->nanoseconds` off the instance it is handed, and the type declaration is only resolved when a non-null value is passed. Calling `wait()` or `wait(null)` therefore works without it, and a caller that has a `Duration` to pass necessarily has the class already. The component README says where to get it. One divergence worth a decision: native reports the negative-timeout error as argument #2, ```c if (timeout->duration.negative) { zend_argument_value_error(2, "must not be negative"); ``` which looks like a leftover from the old signature, since `$timeout` is argument #1 and #2 is now `$maxEvents`. No phpt covers it. The polyfill reports #1; if upstream keeps #2 I will align. Commits ------- 5d1b0f3 [IoPoll] Take Time\Duration in Context::wait()
Adds the new
Time\Durationclass added to PHP 8.6. This class is part of the newTimeextension.