我正在尝试使用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();
答案 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();