Skip to content

Add options to dump function #48474

@GromNaN

Description

@GromNaN

Description

Following #48432 (review)

It would be helpful to pass options to the dump() and dd() functions.

  1. @nicolas-grekas propose to use named arguments, and an option builder.
$options = VarDumper::options()->trace()->maxDepth(4)->toArray();
dump($var, ...$options);

// or

dump($var, _trace: true, _max_depth: 4);

The underscore prefix is required to prevent conflict with named arguments that could be dynamically set.

  1. In addition, I propose to return the options builder and actually display the dump in a __destruct. So that it is more fluent.
dump($var)->trace()->maxDepth(4);

A last method can be added in case the __destruct would not be called (return value affected to a variable).

dump($var)->trace()->maxDepth(4)->render();

To be complete, we need the same capability for the dump helper in Twig.

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRFC = Request For Comments (proposals about features that you want to be discussed)VarDumper

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      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