Bug #74561 [Com]: DateInterval properties not reflected
Edit report at https://bugs.php.net/bug.php?id=74561&edit=1
ID: 74561
Comment by: fabien dot villepinte at gmail dot com
Reported by: fabien dot villepinte at gmail dot com
Summary: DateInterval properties not reflected
Status: Open
Type: Bug
Package: Date/time related
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2017-05-09 12:34:11] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74561&edit=1
Thread (3 messages)