0

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

PHP Fatal error:  Uncaught Error: Class 'Symfony\Component\Console\Application' 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 'Symfony\Component\Console\Application' 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 Symfony\Component\Console\Application;

require 'vendor/autoload.php';

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

$app->add(new Acme\ShowCommand());
$app->run();
1
  • are you sure that the console component is installed correctly ? whats the output of php composer.phar info from the directly where the projects files are ? Commented Dec 12, 2016 at 5:59

2 Answers 2

6

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

#! usr/bin/env php
<?php 

require 'vendor/autoload.php';

use Symfony\Component\Console\Application;

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

$app->add(new Acme\ShowCommand());
$app->run();
Sign up to request clarification or add additional context in comments.

Comments

-1

Some classes can be absent in your vendor. So, it can be resolved by a composer install.

3 Comments

Are you sure about this? The other answer, which got accepted by the OP, indicates that moving a line around helped. Please add some explanation to your answer such that others can learn from it
Yes. But, indeed, in this case, to place the use statement after the require vendor/autoload.php is the good answer. But, this php fatal error can be displayed too, if your vendor are not completly installed.
Please add all clarification to your answer by editing it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.