eldan88 Posted July 12, 2014 Share Posted July 12, 2014 Hey Guys. I am new to using namespaces. I am trying to use it on the code below but it keeps giving me an error message saying Class 'lesson_one\Lecture' not found I am not sure what I am doing wrong here... I have provided an example below. I know there is a duplicate conditional statement. But I am just working with this code to test out the namespace. Any help would be really appreciated! namespace lesson_one; abstract class Lesson { protected $duration; const FIXED = 1; const TIMED = 2; private $costtype; function __construct($duration, $costtype=1) { $this->duration = $duration; $this->costtype = $costtype; } function cost(){ switch($this->costtype) { case self::TIMED: return (5* $this->duration); break; case self::FIXED: return 30; break; default: $this->costtype = self::FIXED; return 30; } } function chargeType() { switch($this->costtype) { case SELF::TIMED: return "hourly rate"; break; case self::FIXED : return "fixed rate"; break; default: $this->costtype = self::FIXED; return "fixed rate"; } } } class Lecture extends Lesson { } class Seminar extends Lesson { } //echo Lesson::FIXED; $lecture = new \lesson_one\Lecture("5", Lesson1::FIXED); echo $lecture->cost(). "<br>"; echo $lecture->chargeType(). "<br>"; Quote Link to comment Share on other sites More sharing options...
eldan88 Posted July 12, 2014 Author Share Posted July 12, 2014 Also I even tried adding the namespace to the extended class and my IDE says "Unnecessary fully qualified name" namespace lesson_one; abstract class Lesson { // Some code here } class Lecture extends \lesson_one\Lesson { } Quote Link to comment Share on other sites More sharing options...
eldan88 Posted July 14, 2014 Author Share Posted July 14, 2014 Can someone please help me with this issue... Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted July 14, 2014 Share Posted July 14, 2014 Can you show us your entire code (especially if it's in separate files), and the exact error message? Also, are you using an autoloader? 1 Quote Link to comment Share on other sites More sharing options...
gizmola Posted July 15, 2014 Share Posted July 15, 2014 Hi Eldan, At the top of your class file you establish that the namespace is lesson_one. This means that until such time as you change namespace, you are working in the lesson_one namespace. Thus it makes no sense that you would refer to specific names paths later in the same file. If you're including that in a script, then the namespace specifier would make sense. Also, as Kevin pointed out, Autoloaders make all of this detail superfluous, and you wouldn't use the namespace to access those either, because they'd be autoloader and available typically with the "use" keyword. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.