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

From: Date: Thu, 14 Apr 2022 08:44:22 +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-240947@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8351 Comment Author: derickr > internal structure of the DateTimeImmutable class is known to the user. That is not true. It encapsulates a lot more things then the three properties that you see when doing serialisation or var_dump(). These properties should indeed be read only, but that wasn't functionality that didn't exist until PHP 8.1. I am also unsure as to whether we should do anything here. I don't really want them as "real properties" (they're more like SQL's materialised views), and marking them "readonly" is only possible from 8.2 onwards, as we can't really break existing code (calling __construct() itself) either. As such, I agree with @bwoebi that this is similar to using reflection overriding a private property, and that we shouldn't really do anything here, even though it isn't technically 100% encapsulated.

« previous php.bugs (#240947) next »