2014-07-13 247 views
0

我面临一个很奇怪的错误,虽然它似乎我已经做了所有需要PHP致命错误:类“X”未找到

错误:PHP Fatal error: Class 'Login' not found

代码:

<?php 

//Includes... 
require_once(__DIR__ . "/base/request.abstract.php"); 

//Entry point... 
try { 
    //What should i do ? the class is in the same file so what to do so php recognize it ? 
    echo (new Login($_REQUEST['request']))->processRequest(); 
} catch (Exception $e) { 
    echo json_encode(array('error' => $e->getMessage())); 
} 

//Implementation... 
class Login extends RequestAbstract 
{ 
    public function processRequest() 
    { 

    } 
} 
+0

“看来我已经完成了所有的要求”显然不是,因此错误。不知道还有什么我们可以说 –

+0

[看看这个问题](http://stackoverflow.com/questions/3458756/does-the-order-of-class-definition-matter-in-php) –

+0

这就是为什么我说'看起来' –

回答

3

您正在尝试在声明之前使用Login类。将你的类移动到try/catch块上面,你的代码就可以工作。 As the manual says,“应该在实例化之前定义类(在某些情况下,这是一个要求)”。

+0

LOL这实际上工作:D idk为什么有人投票给你... –

+0

@DanielEugen如果实例化和声明在同一个文件中,这应该不会导致错误; http://codepad.viper-7.com/d0IwEY – Steve

+0

@ user574632是的,但我想在声明之前访问类......这是我的代码中的问题。 –

相关问题