10000 [PropertyAccess] Auto-cast from DateTime to DateTimeImmutable when ap… · symfony/symfony@9b6495a · GitHub
[go: up one dir, main page]

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

+9
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)
0