php / php/php-src

DateInterval::$from_string undefined until a lookup

Open
#14,612 2 comments 0 reactions 1 assignee View on GitHub

@derickr is already working on this.

Since Jun 21, 2024.

Bug Extension: date Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?php
$dateInterval = new DateInterval('PT1S'); // or even DateInterval::createFromDateString('1 second')

var_dump(isset($dateInterval->from_string));

(array) $dateInterval; // or print_r() or var_dump()

var_dump(isset($dateInterval->from_string));

Resulted in this output:

bool(false)
bool(true)

But I expected this output instead:

bool(true)
bool(true)

According documentation property $from_string should be always defined (in PHP >= 8.2) but it isn't. Dump of the object initializes the property "ad hoc". var_dump() shouldn't have side effects IMHO.

PHP Version

PHP 8.2.20

Operating System

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.