Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VarDumper] Add support for custom output formats #20368

Open
wants to merge 1 commit into
base: 7.1
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions components/var_dumper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,41 @@
return $dumper->dump($cloner->cloneVar($var));
});

The ``dq()`` Function

Check failure on line 515 in components/var_dumper.rst

View workflow job for this annotation

GitHub Actions / Lint (DOCtor-RST)

Please ensure title "The dq() Function" and underline length are matching
--------------------

When working with database queries, you can use the ``dq()`` function to dump a
query builder instance with all parameter bindings interpolated into the SQL string.
This is particularly useful for debugging complex queries:

.. code-block:: php

Check failure on line 522 in components/var_dumper.rst

View workflow job for this annotation

GitHub Actions / Lint (DOCtor-RST)

Please do not use ".. code-block:: php", use "::" instead.

use Doctrine\ORM\QueryBuilder;
// ... your query builder setup
$qb = $entityManager->createQueryBuilder()
->select('u')
->from('App\Entity\User', 'u')
->where('u.active = :active')
->setParameter('active', true);

dq($qb); // This will dump the complete SQL with parameters and exit

The ``dq()`` function will:

* Show the complete SQL query with all parameters replaced
* Set a 500 HTTP status code (in web requests)
* Exit the script after dumping (similar to ``dd()``)

.. versionadded:: 7.1

Check failure on line 540 in components/var_dumper.rst

View workflow job for this annotation

GitHub Actions / Lint (DOCtor-RST)

Please add a blank line after ".. versionadded:: 7.1
The ``dq()`` function was introduced in Symfony 7.1.

.. note::

The ``dq()`` function works with any object that implements the ``toSql()`` and
``getBindings()`` methods, making it compatible with Laravel's Query Builder,
Doctrine's QueryBuilder (with some adapters), and similar implementations.


Cloners
~~~~~~~

Expand Down
Loading