[英]PHP Fatal error: Uncaught Error: Class 'Acme\RegisterUser' not found
I'm learning all about namespaces in PHP but I haven't got a clue what I am doing wrong? 我正在学习有关PHP中名称空间的全部知识,但是我不知道我在做什么错?
Here is my directory structure: 这是我的目录结构:
/review
├── index.php
├── RegisterUser.php
└── AuthController.php
index.php index.php
<?php
$registration = new Acme\RegisterUser;
$authController = new Acme\AuthController($registration);
$authController->register();
RegisterUser.php RegisterUser.php
<?php namespace Acme;
class RegisterUser
{
public function execute(array $data, $listener)
{
var_dump('registering the user');
$listener->userRegisteredSuccessfully();
}
}
and AuthController.php 和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');
}
}
What am I doing wrong? 我究竟做错了什么?
I am using PHP version PHP 7.1.0RC6 (cli) (built: Nov 9 2016 04:45:59) ( NTS )
我正在使用PHP版本
PHP 7.1.0RC6 (cli) (built: Nov 9 2016 04:45:59) ( NTS )
Error: 错误:
> $ 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
您必须首先通过自动加载或手动包含这些类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.