Sevalla is the all-in-one PaaS for your web projects. Host and deploy your applications, databases, object storage, and static sites. Enjoy advanced deployment pipelines, a complete database studio, instant preview apps, and one-click templates. The pricing is simple: no hidden fees, no seat-based pricing, and you pay only for what you use. Get real human support from developers.

Get started now with a $50 credit at Sevalla.com.

Symfony now has an improved dump function

Original – by Freek Van der Herten – 2 minute read

Let's talk a little bit about Symfony's dump function. It's part of their VarDumper component. The function can dump a variable to the screen or browser in a nicer format than PHP's native var_dump. In the recently released Symfony 3.4 and Symfony 4 the function got a nice little improvement that I'd like to highlight in this post.

You probably already know that you can dump stuff like this:

dump($object);

Nothing too fancy. But if you did this in previous versions of the framework it would blow up:

// dump didn't return anything so method is getting called on null ☠️
dump($object)->method();

I was quite annoyed with this so I submitted a PR to Symfony that let dump return the things that it was given. So now you can just wrap the function around any variable even if there are methods being called on it.

// in Symfony 3.4 and 4.x this just works ????
dump($object)->method();

When dumping multiple things, they all get returned. So you could dump all arguments passed to a function like this.

$object->method(...dump($arg1, $arg2, $arg3));

If you are using Laravel you'll be happy to know that Laravel just uses Symfony's dump function, so you can make use of this little improvement in Laravel too.

Happy dumping! ????

Stay up to date with all things Laravel, PHP, and JavaScript.

You can follow me on these platforms:

On all these platforms, regularly share programming tips, and what I myself have learned in ongoing projects.

Every month I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.