[php-src] Issue #8351: explicit `__construct` call for \DateTimeImmutable object would break immutable

From: Date: Tue, 12 Apr 2022 14:07:55 +0000
Subject: [php-src] Issue #8351: explicit `__construct` call for \DateTimeImmutable object would break immutable
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-240900@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8351 Comment Author: cmb69 > I propose to give readonly to each of the properties of \DateTimeImmutable. That would require to actually have these properties, but so far their state is tracked internally. Something like the following might solve the issue, though: ````.diff ext/date/php_date.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index d607a07420..db21ba21a5 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2208,6 +2208,9 @@ PHPAPI bool php_date_initialize(php_date_obj *dateobj, const char *time_str, siz int options = 0; if (dateobj->time) { + if (dateobj->std.ce == date_ce_immutable && flags & PHP_DATE_INIT_CTOR) { + zend_throw_exception_ex(NULL, 0, "nonono"); + } timelib_time_dtor(dateobj->time); } if (format) { ```` @derickr, what do you think?

« previous php.bugs (#240900) next »