6

I'm trying to import a file and instantiate a class that's outside the namespace. The require_once is working, but I'm getting a class not found error when instantiating it. Is there any way around this?

walther
  • 13,466
  • 5
  • 41
  • 67
George Ionita
  • 63
  • 1
  • 6
  • http://stackoverflow.com/questions/6000996/cakephp-and-namespaces. check this link – Alive to die - Anant May 27 '15 at 14:17
  • @anantkumarsingh I did look at that thread before but couldn't find a solution. Basically it is just not looking for the class in the file I've imported, because it's restricted to the namespace it's currently in. Was wondering if there's other way around this except copy pasting the file so it can be accessible from the namespace. – George Ionita May 27 '15 at 14:23
  • When receiving errors, please always add the _complete_ error message including possible stacktraces. Also check **http://stackoverflow.com/q/30460247/1392379** – ndm May 27 '15 at 14:24
  • you can create it as component, helper and you can use it. – Alive to die - Anant May 27 '15 at 14:24
  • 1
    I've just sorted it, all that was needed was a backlash before, like this : $waad = new \WAAD_Authentication(); . Thank you anyway ! – George Ionita May 27 '15 at 14:25

1 Answers1

10

Simply prefix the class name with a backslash, like so

$waad = new \WAAD_Authentication();
Gregory Cosmo Haun
  • 1,499
  • 17
  • 25