PHPで名前空間に関するすべてのことを学んでいますが、私が間違っていることを知りませんでしたか?ここでPHP致命的なエラー:キャッチされていないエラー:クラス 'Acme RegisterUser'が見つかりません
私のディレクトリ構造です:
/review
├── index.php
├── RegisterUser.php
└── AuthController.php
のindex.php
<?php
$registration = new Acme\RegisterUser;
$authController = new Acme\AuthController($registration);
$authController->register();
RegisterUser.php
<?php namespace Acme;
class RegisterUser
{
public function execute(array $data, $listener)
{
var_dump('registering the user');
$listener->userRegisteredSuccessfully();
}
}
とAuthController.php
<?php namespace Acme;
class AuthController {
protected $registration;
public function __construct(RegisterUser $registration, $listener) {
$this->registration = $registration;
}
public function register() {
$this->registration->execute([], $this);
}
public function userRegisteredSuccessfully() {
var_dump('created successsfully. redirect somewhere');
}
public function userRegisteredFailed() {
var_dump('created unsuccessfully. redirect back');
}
}
私は間違っていますか?私はPHPのバージョンPHP 7.1.0RC6 (cli) (built: Nov 9 2016 04:45:59) (NTS)
エラーを使用しています
:
> $ php index.php [±master ●]
PHP Fatal error: Uncaught Error: Class 'Acme\RegisterUser' not found in /Users/dan/Desktop/oop/src/review/index.php:2
Stack trace:
#0 {main}
thrown in /Users/dan/Desktop/oop/src/review/index.php on line 2
Fatal error: Uncaught Error: Class 'Acme\RegisterUser' not found in /Users/dan/Desktop/oop/src/review/index.php:2
Stack trace:
#0 {main}
thrown in /Users/dan/Desktop/oop/src/review/index.php on line 2
完全修飾クラス名(例:new \ Acme \ RegisterUser)の前にスラッシュを挿入するとどうなりますか? –
どのようにクラスを含むファイルを含めるのですか?手動で?オートローダ? – Clive
適切なクラスをロードする必要があります。http://php.net/manual/en/language.oop5.autoload.php –