Skip to content
Advertisement

PHP Fatal error: Uncaught Error: Class ‘SymfonyComponentConsoleApplication’ not found

I am trying to create a simple CLI app with PHP but I keep getting:

PHP Fatal error:  Uncaught Error: Class 'SymfonyComponentConsoleApplication' not found in /Applications/MAMP/htdocs/newcli/dan.php:6
Stack trace:
#0 {main}
  thrown in /Applications/MAMP/htdocs/newcli/dan.php on line 6

Fatal error: Uncaught Error: Class 'SymfonyComponentConsoleApplication' not found in /Applications/MAMP/htdocs/newcli/dan.php:6
Stack trace:
#0 {main}
  thrown in /Applications/MAMP/htdocs/newcli/dan.php on line 6

What am I doing wrong? My PHP version: PHP 7.1.0RC6 (cli) (built: Nov 9 2016 04:45:59) ( NTS )

dan.php:

#! usr/bin/env php
<?php use SymfonyComponentConsoleApplication;

require 'vendor/autoload.php';

$app = new Application('Task App', '1.0');

$app->add(new AcmeShowCommand());
$app->run();

Advertisement

Answer

The use statement must be placed after the require 'vendor/autoload.php'

#! usr/bin/env php
<?php 

require 'vendor/autoload.php';

use SymfonyComponentConsoleApplication;

$app = new Application('Task App', '1.0');

$app->add(new AcmeShowCommand());
$app->run();
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement