note 124885 added to dateinterval.construct

From: Date: Sun, 05 Apr 2020 10:51:45 +0000
Subject: note 124885 added to dateinterval.construct
Groups: php.notes 
Request: Send a blank email to php-notes+get-214421@lists.php.net to get a copy of this message
If you'd like to persist an interval object in a DB it could be handy to implement the __toString() method. A formatted interval value can be easier to read by a human than the output of serialize. Here's an example: <?php namespace App; class DateInterval extends \DateInterval { public function __toString() { return $this->format('P%yY%mM%dDT%hH%iM%sS'); } } $interval1 = new DateInterval('P1Y'); $interval2 = new DateInterval(strval($interval1)); assert($interval1 == $interval2); ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.195 (proxied: 188.146.35.162) ---- Manual Page -- http://php.net/manual/en/dateinterval.construct.php Edit -- https://master.php.net/note/edit/124885 Del: integrated -- https://master.php.net/note/delete/124885/integrated Del: useless -- https://master.php.net/note/delete/124885/useless Del: bad code -- https://master.php.net/note/delete/124885/bad+code Del: spam -- https://master.php.net/note/delete/124885/spam Del: non-english -- https://master.php.net/note/delete/124885/non-english Del: in docs -- https://master.php.net/note/delete/124885/in+docs Del: other reasons-- https://master.php.net/note/delete/124885 Reject -- https://master.php.net/note/reject/124885 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214421) next »