|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-05-09 12:38 UTC] fabien dot villepinte at gmail dot com
[2017-05-14 18:35 UTC] heiglandreas@php.net
-Status: Open
+Status: Duplicate
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 10:00:02 2025 UTC |
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