It happens that I work with PHP outside of Laravel or Symfony, typically when working on a lib, and I always miss the
dd function. Do you remember
print_r? I don't want to have to use that!
I found a simple way to always preload PHP library. I shouldn't say preload tho, this as nothing to do with the PHP 7.4 preload feature. It's basically a way to include a php file, before the normal PHP cycle starts. This is especially useful if you're working on a simple 15-line script without Composer.
It's all built-in PHP and it has been here for a looong time: https://php.net/auto-prepend-file.
How to always load
Create a new directory somewhere (typically in your dotfiles/
composer require symfony/var-dumper
Create a simple
prepend.phpwith the content shown below
Note: I don't recommend defining the
- Open your
php.iniconfiguration file and add the following
- You can now access
isYolofrom anywhere, including psysh console!
I have been using this for over a year now, I never encountered any confict, error like "function already defined" or whatsoever.