Bug #74561 [NEW]: DateInterval properties not reflected

From: Date: Tue, 09 May 2017 12:34:16 +0000
Subject: Bug #74561 [NEW]: DateInterval properties not reflected
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209025@lists.php.net to get a copy of this message
From:             fabien dot villepinte at gmail dot com
Operating system: 
PHP version:      Irrelevant
Package:          Date/time related
Bug Type:         Bug
Bug description:DateInterval properties not reflected

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

-- 
Edit bug report at https://bugs.php.net/bug.php?id=74561&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=74561&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=74561&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=74561&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=74561&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=74561&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=74561&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=74561&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=74561&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=74561&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=74561&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=74561&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=74561&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=74561&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74561&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=74561&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=74561&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=74561&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74561&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=74561&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=74561&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#209025) next »