2016-04-21 71 views
1

我有一个结构,像这样:扩展与命名空间一类是说找不到类

index.php 
core 
    Exceptions 
    ExceptionCore.php 
    ExceptionUtil.php 
Vendor 
    autoload stuff 

索引文件:

<?php 

require 'vendor/autoload.php'; 

new \core\Exceptions\ExceptionCore\ExceptionCore(); 

ExceptionCore:

<?php 

Namespace core\Exceptions\ExceptionCore; 

Class ExceptionCore 
{ 
    public function __construct() 
    { 
     echo 'fffhf'; 
    } 
} 

但我得到错误:

Fatal error: Uncaught Error: Class 'core\Exceptions\ExceptionCore\ExceptionCore' not found in C:\xampp\htdocs\user\index.php:5 Stack trace: #0 {main} thrown in C:\xampp\htdocs\user\index.php on line 5

+0

被保存在正确的位置的ExceptionCore文件? –

+0

据我所知http://i.imgur.com/A7sPG6R.png – 4334738290

+0

该文件需要在'user/core/Exceptions/ExceptionCore' –

回答

1

自动装载机希望在文件core/Exceptions/ExceptionCore/ExceptionCore.php中找到类core\Exceptions\ExceptionCore\ExceptionCore

了解更多关于PSR-0PRS-4的标准。

+0

我该怎么做才能在当前结构中找到正确的文件......如果需要,我可以重命名命名空间。 – 4334738290

+1

从命名空间中移除'ExceptionCore'。 –

0

索引文件

<?php 

require 'vendor/autoload.php'; 

new core\Exceptions\ExceptionCore\ExceptionCore(); ///delete 

ExceptionCore:

Namespace core\Exceptions\ExceptionCore; 

Class ExceptionCore 
{ 
    public function __construct() 
    { 
     echo 'fffhf'; 
    } 
} 

code is work

+0

致命错误:未捕获错误:未找到类'core \ Exceptions \ ExceptionCore \ ExceptionCore' – 4334738290

+0

已测试代码。请再看一遍。 – Semu

相关问题