Using composer-added dependencies in the php interactive shell

Viewed 552

I am trying to use my composer added dependencies in the php shell, but it does not work.

I am using this gist [ https://gist.github.com/gigorok/5ca39384635113495796 ]

php -a -d auto_prepend_file=./vendor/autoload.php

I attempt to run, the same :

use Carbon\Carbon;
Carbon::parse('today');

After this line I get: PHP Warning: Uncaught Error: Class 'Carbon' not found in php shell code:1

It is worth noting that I have a codecept tests running which use Carbon with the same use statement and they work.

2 Answers

As stated in PHP documentation, autoloading doesn't work in interactive shell:

Autoloading is not available if using PHP in CLI interactive mode

This may help.

cd /your/application/dir
rm bootstrap/compiled.php
rm -rf vendor
composer install --no-dev
Related