0

I was working in a scratch file and tried to use a non native function (muscle memory) and of cause it threw an error

The PHP Fatal error: Uncaught Error: Call to undefined function dd() in .../.scratch.php

What I wanted to know is can I make dd() for example available globally across all projects/scratch files without having to autoload it myself.

Essentially you would set a PSR-4 autoload path or directory to include.

After exploring the settings I didn't come up with a way of doing it so this is what I did instead.

composer global require --dev symfony/var-dumper
<?php
include $_SERVER['APPDATA']. '/Composer/vendor/autoload.php';
$var = '';
dd($var);
DarkBee
  • 16,592
  • 6
  • 46
  • 58
TarranJones
  • 4,084
  • 2
  • 38
  • 55
  • 1
    The IDE (PhpStorm in this case) will NOT add such a custom code or you. It has no such options. BUT you can do it in your PHP. Just configure `auto_prepend_file` in your php.ini and see the docs: https://www.php.net/manual/en/ini.core.php#ini.auto-prepend-file – LazyOne Aug 03 '22 at 10:32
  • 1
    In case of PhpStorm, you can pass such params to your PHP Interpreter or maybe even Run/Debug Configuration (need to check it first). As you know, you can also pass config params directly to PHP executable via command line parameters ( `-d` -- https://www.php.net/manual/en/features.commandline.options.php ) – LazyOne Aug 03 '22 at 10:32

1 Answers1

0

I just complete the answer above

To use 'vendor' projects and components in your phpstorm scratch file
include the file vendor/autoload.php
and for the example to check a Symfony component... :

require '/path/to/my/project/app/vendor/autoload.php';

use Symfony\Component\Intl\Currencies;

\Locale::setDefault('sv');
$res = Currencies::getSymbol('SEK');
print_r($res);
nilsM
  • 107
  • 8