2

I am facing a very strange error although it seems that i have done all the requires

Error: PHP Fatal error: Class 'Login' not found

Code:

<?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()
    {

    }
}
Daniel Eugen
  • 2,712
  • 8
  • 33
  • 56

1 Answers1

4

You're trying to use your Login class before it's been declared. Move your class above the try/catch block, and your code will work. As the manual says, "Classes should be defined before instantiation (and in some cases this is a requirement)."

Defining a class before it is instantiated is a requirement when a Class is implementing an interface.

Julian
  • 4,396
  • 5
  • 39
  • 51
Alex P
  • 5,942
  • 2
  • 23
  • 30
  • @DanielEugen This should not cause the error if the instantiation and declaration are in the same file; http://codepad.viper-7.com/d0IwEY – Steve Jul 13 '14 at 21:58
  • @user574632 yea but i was trying to access the class before declaration... that was the problem in my code. – Daniel Eugen Jul 13 '14 at 22:01