Skip to content

Commit 70fb1ec

Browse files
authored
Warn users about performance issues with DateTime objects in setParameter() (doctrine#8114)
1 parent 73ec483 commit 70fb1ec

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

docs/en/reference/query-builder.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,21 @@ and for managed entities. If you want to set a type explicitly you can call
255255
the third argument to ``setParameter()`` explicitly. It accepts either a PDO
256256
type or a DBAL Type name for conversion.
257257

258+
.. note::
259+
260+
Even though passing DateTime instance is allowed, it impacts performance
261+
as by default there is an attempt to load metadata for object, and if it's not found,
262+
type is inferred from the original value.
263+
264+
.. code-block:: php
265+
266+
<?php
267+
268+
use Doctrine\DBAL\Types\Types;
269+
270+
// prevents attempt to load metadata for date time class, improving performance
271+
$qb->setParameter('date', new \DateTimeImmutable(), Types::DATE_IMMUTABLE)
272+
258273
If you've got several parameters to bind to your query, you can
259274
also use setParameters() instead of setParameter() with the
260275
following syntax:
@@ -581,4 +596,3 @@ same query of example 6 written using
581596
->add('from', new Expr\From('User', 'u'))
582597
->add('where', new Expr\Comparison('u.id', '=', '?1'))
583598
->add('orderBy', new Expr\OrderBy('u.name', 'ASC'));
584-

0 commit comments

Comments
 (0)