Adds functions dumpf() and ddf() to Symfony's VarDumper component to be used in CLI scripts to dump to a file.

2.1.3 2022-08-02 21:11 UTC



Serendipity HQ VarDumper F

Adds functions `dumpf()` and `ddf()` to [Symfony's VarDumper component]( that write the dump to a file.

68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736572656e6469706974795f68712f636f6d706f6e656e742d7661722d64756d7065722d662e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736572656e6469706974795f68712f636f6d706f6e656e742d7661722d64756d7065722d663f636f6c6f723d253233383839324246267374796c653d666c61742d737175617265266c6f676f3d706870

Supports: 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545342e342d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545352e342d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545362e302d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79

Tested with: 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545342e342d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545352e342d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253545362e302d3333333f7374796c653d666c61742d737175617265266c6f676f3d73796d666f6e79

Current Status

Coverage Maintainability Rating Quality Gate Status Reliability Rating Security Rating Technical Debt Vulnerabilities

Phan PHPStan PSalm PHPUnit Composer PHP CS Fixer Rector

Do you like this library?

or run
composer global require symfony/thanks && composer thanks
to say thank you to all libraries you use in your current project, this included!

Install VarDumper CLI to HTML via Composer

$ composer require serendipity_hq/component-var-dumper-f --dev

This library follows the versioning conventions.


The library provides two functions: dumpf() and ddf().

They work exactly like the Symfony's VarDumper built ones dump() and dd(), with those specifities:

  1. Both dumpf() and ddf() can be used only in scripts that run in the command line;
  2. Both requires the first parameter is null or an array with some options.

The simplest usage is this:

$var = [
    'a simple string' => "in an array of 5 elements",
    'a float' => 1.0,
    'an integer' => 1,
    'a boolean' => true,
    'an empty array' => [],
dumpf(null, $var);
ddf(null, $var);

The result will be an HTML file with a random name that contains the dump of $var.

Opening the file you will see

For more examples of outputs, consult the Symfony's VarDumper documentation about Dump Examples and Output.

Specifying the dumped file

You can specify the file of the dump passing its full path name as first argument:

dumpf('~/path/to/your/folder/filename', $var);
ddf('~/path/to/your/folder/filename', $var);

You can use a name like filename or like filename.html: the resulting file will always have one .html extension (filename.html).

Passing options

Both functions accepts as first argument an array.

The passed array can contain any of the options that you can pass to a Symfony's VarDumper Cloner (reference).

The only additional option you can pass is the file, whit which you can specify the name of the dumped file:

dumpf(['file' => 'dump_var', 'maxDepth' => 2], $var);
ddf(['file' => 'dump_var.html', 'maxDepth' => 5], $var);

In both cases, the file dump_var.html will be generated.

What happens if the file already exists

The new dump will be added to the already existing file.

So, if you call dumpf() three times in your CLI script, then the resulting file dump will have three dumps in it.

If you run again the script, the resulting file dump will now contain six dumps in it: the three from the first run and the three from the second run.

To get a fresh dump, simply remove the dumped files.

Do you like this library?

or run
composer global require symfony/thanks && composer thanks
to say thank you to all libraries you use in your current project, this included!