Skip to content

Time\Duration::fromIso8601DurationString() ignores everything after a NUL byte. #24504

Closed

Description

@azjezz

Description

The following code:

<?php

foreach (["PT1Sgarbage", "PT1S\0garbage", "PT1H\0x", "PT1S\0"] as $input) {
    try {
        $d = Time\Duration::fromIso8601DurationString($input);
        printf("%-18s => accepted: %d s\n", json_encode($input), $d->seconds);
    } catch (Time\TimeException $e) {
        printf("%-18s => rejected: %s\n", json_encode($input), $e->getMessage());
    }
}

Resulted in this output:

"PT1Sgarbage"      => rejected: The ISO 8601 duration string could not be parsed
"PT1S\u0000garbage" => accepted: 1 s
"PT1H\u0000x"      => accepted: 3600 s
"PT1S\u0000"       => accepted: 1 s

But I expected this output instead:

"PT1Sgarbage"      => rejected
"PT1S\u0000garbage" => rejected
"PT1H\u0000x"      => rejected
"PT1S\u0000"       => rejected

PHP Version

PHP 8.6.0RC3 (cli) (built: Oct 20 2026 18:44:56) (NTS)
Copyright © The PHP Group and Contributors
Zend Engine v4.6.0RC3, Copyright © Zend by Perforce
    with Zend OPcache v8.6.0RC3, Copyright ©, by Zend by Perforce

Operating System

MacOS

Activity

  1. iliaal commented on Oct 22, 2026

    @iliaal
    Member

    Fixed by #24357, merged into PHP-8.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions