PHP致命错误:未捕获错误:类' Symfony \ Component \ Console \ Application'找不到

时间:2016-12-12 05:37:59

标签: php symfony

我正在尝试使用PHP创建一个简单的CLI应用程序,但我一直在:

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

我做错了什么?我的PHP版本: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 个答案:

答案 0 :(得分:4)

use语句必须放在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();