|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-09-11 13:26 UTC] steven at gowebprint dot com
Description: ------------ I am trying to extend DateTime and DaveInterval to add extra functionality to the core classes, but I have been unable to write to $this->days internally to the object. As a side note, I have been able to cause a seg fault within our application when writing to $interval->days = 100 externally, but unable to reproduce on a small script. Test script: --------------- http://pastebin.com/tBay704K Expected result: ---------------- object(DateInterval)[3] public 'y' => int 1 public 'm' => int 0 public 'd' => int 0 public 'h' => int 0 public 'i' => int 0 public 's' => int 0 public 'weekday' => int 0 public 'weekday_behavior' => int 0 public 'first_last_day_of' => int 0 public 'invert' => int 1 public 'days' => int 365 public 'special_type' => int 0 public 'special_amount' => int 0 public 'have_weekday_relative' => int 0 public 'have_special_relative' => int 0 object(test\DateInterval)[4] public 'days' => int 365 public 'y' => int 1 public 'm' => int 0 public 'd' => int 0 public 'h' => int 0 public 'i' => int 0 public 's' => int 0 public 'weekday' => int 0 public 'weekday_behavior' => int 0 public 'first_last_day_of' => int 0 public 'invert' => int 1 public 'special_type' => int 0 public 'special_amount' => int 0 public 'have_weekday_relative' => int 0 public 'have_special_relative' => int 0 Actual result: -------------- object(DateInterval)[3] public 'y' => int 1 public 'm' => int 0 public 'd' => int 0 public 'h' => int 0 public 'i' => int 0 public 's' => int 0 public 'weekday' => int 0 public 'weekday_behavior' => int 0 public 'first_last_day_of' => int 0 public 'invert' => int 1 public 'days' => int 365 public 'special_type' => int 0 public 'special_amount' => int 0 public 'have_weekday_relative' => int 0 public 'have_special_relative' => int 0 object(test\DateInterval)[4] public 'days' => boolean false public 'y' => int 1 public 'm' => int 0 public 'd' => int 0 public 'h' => int 0 public 'i' => int 0 public 's' => int 0 public 'weekday' => int 0 public 'weekday_behavior' => int 0 public 'first_last_day_of' => int 0 public 'invert' => int 1 public 'special_type' => int 0 public 'special_amount' => int 0 public 'have_weekday_relative' => int 0 public 'have_special_relative' => int 0 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 01:00:01 2025 UTC |
You are right. I have extended DateTime object and overrides the diff method with public function diff ($datetime2 , $absolute = false){ return new DateInterval(parent::diff($datetime2,$absolute)); } If you look at the sample code that would be return the DateInterval in the test namespace. Since I am overriding the diff method I want to return a DateInterval object that behaves like it would from \DateTime which includes a populated days property , but I have no way of setting the days property or telling \DateTime to return a different DateInterval object, so I am unable to return a DateInteral object with a days property filled and returned from the diff method as expected. The manual says: If the DateInterval object was created by DateTime::diff(), then this is the total number of days between the start and end dates. Otherwise, days will be FALSE. This is the method I have overridden and I am trying to return a extended DateInterval object, whilst keeping the all of the DateInterval property's intact including days.