On 16/03/2021 18:56, Moritz Friedrich wrote:
Again, I’m not attached to `__toString()`. Having another helper method or a 
special formatting constant, as suggested by others in this thread, would 
likewise be a viable option. I’d merely prefer to have a built-in way of 
parsing*and*  composing time intervals as per the ISO specification, making the 
API consistent and easing communication with non-PHP systems.


Would a reasonable way forward be to have such a named method, and have it throw an exception if the instance is not representable in that form?

That way, you'd be guaranteed that new DateInterval($period->toIsoPeriodString()) would result in an equivalent object, rather than discarding special relative values.

Regards,

--
Rowan Tommins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to