Skip to content

Commit 9b6495a

Browse files
[PropertyAccess] Auto-cast from DateTime to DateTimeImmutable when appropriate
1 parent 51889c0 commit 9b6495a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ public function setValue(object|array &$objectOrArray, string|PropertyPathInterf
134134

135135
return;
136136
} catch (\TypeError $e) {
137+
try {
138+
if ($value instanceof \DateTime && __FILE__ === $e->getTrace()[0]['file']) {
139+
$this->writeProperty($zval, $propertyPath, \DateTimeImmutable::createFromInterface($value));
140+
141+
return;
142+
}
143+
} catch (\TypeError) {
144+
// ignore
145+
}
137146
self::throwInvalidArgumentException($e->getMessage(), $e->getTrace(), 0, $propertyPath, $e);
138147
// It wasn't thrown in this class so rethrow it
139148
throw $e;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy