php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74561 DateInterval properties not reflected
Submitted: 2017-05-09 12:34 UTC Modified: 2017-05-14 18:35 UTC
From: fabien dot villepinte at gmail dot com Assigned:
Status: Duplicate Package: Date/time related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: fabien dot villepinte at gmail dot com
New email:
PHP Version: OS:

 

 [2017-05-09 12:34 UTC] fabien dot villepinte at gmail dot com
Description:
------------
DateInterval properties are not returned by reflection.

Also some properties are visible only after var_dump().

Test script:
---------------
<?php
function hasProperty($reflectionClass, $name) {
    $prop = null;
    try {
        $prop = $reflectionClass->getProperty($name);
    } catch (ReflectionException $e) {}
    return $prop !== null;
}

$reflectionClass = new ReflectionClass(DateInterval::class);
$props = [
'y',
'm',
'd',
'h',
'i',
's',
'invert',
'days',
'f',
'weekday',
'weekday_behavior',
'first_last_day_of',
'special_type',
'special_amount',
'have_weekday_relative',
'have_special_relative',
];

$interval = new DateInterval('P2Y4DT6H8M');

$test = function () use ($props, $reflectionClass, $interval) {
    foreach ($props as $prop) {
        printf("%s: %d/%d\n", $prop, isset($interval->{$prop}), hasProperty($reflectionClass, $prop));
    }
};

echo "TEST BEFORE VAR_DUMP\n";
$test();

ob_start();
var_dump($interval);
ob_end_clean();

echo "TEST AFTER VAR_DUMP\n";
$test();

Expected result:
----------------
TEST BEFORE VAR_DUMP
y: 1/1
m: 1/1
d: 1/1
h: 1/1
i: 1/1
s: 1/1
invert: 1/1
days: 1/1
f: 1/1
weekday: 1/1
weekday_behavior: 1/1
first_last_day_of: 1/1
special_type: 1/1
special_amount: 1/1
have_weekday_relative: 1/1
have_special_relative: 1/1
TEST AFTER VAR_DUMP
y: 1/1
m: 1/1
d: 1/1
h: 1/1
i: 1/1
s: 1/1
invert: 1/1
days: 1/1
f: 1/1
weekday: 1/1
weekday_behavior: 1/1
first_last_day_of: 1/1
special_type: 1/1
special_amount: 1/1
have_weekday_relative: 1/1
have_special_relative: 1/1

Actual result:
--------------
TEST BEFORE VAR_DUMP
y: 1/0
m: 1/0
d: 1/0
h: 1/0
i: 1/0
s: 1/0
invert: 1/0
days: 1/0
f: 1/0

Notice: Undefined property: DateInterval::$weekday in /in/5tKiH on line 34
weekday: 0/0

Notice: Undefined property: DateInterval::$weekday_behavior in /in/5tKiH on line 34
weekday_behavior: 0/0

Notice: Undefined property: DateInterval::$first_last_day_of in /in/5tKiH on line 34
first_last_day_of: 0/0

Notice: Undefined property: DateInterval::$special_type in /in/5tKiH on line 34
special_type: 0/0

Notice: Undefined property: DateInterval::$special_amount in /in/5tKiH on line 34
special_amount: 0/0

Notice: Undefined property: DateInterval::$have_weekday_relative in /in/5tKiH on line 34
have_weekday_relative: 0/0

Notice: Undefined property: DateInterval::$have_special_relative in /in/5tKiH on line 34
have_special_relative: 0/0
TEST AFTER VAR_DUMP
y: 1/0
m: 1/0
d: 1/0
h: 1/0
i: 1/0
s: 1/0
invert: 1/0
days: 1/0
f: 1/0
weekday: 1/0
weekday_behavior: 1/0
first_last_day_of: 1/0
special_type: 1/0
special_amount: 1/0
have_weekday_relative: 1/0
have_special_relative: 1/0

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-09 12:38 UTC] fabien dot villepinte at gmail dot com
I think this is related to these issues:
https://bugs.php.net/bug.php?id=74054
https://bugs.php.net/bug.php?id=45682
https://bugs.php.net/bug.php?id=53634
https://bugs.php.net/bug.php?id=68940
 [2017-05-14 18:35 UTC] heiglandreas@php.net
-Status: Open +Status: Duplicate
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 14 09:01:27 2024 UTC