0

I have a file that includes a list of classes and a list of functions

include 'Classes.php';
include 'Functions.php';

when I run the code it come up with the error

Fatal error: Cannot declare class PartTimeTeacher, because the name is already in use in /Applications/XAMPP/xamppfiles/htdocs/PHPfolder/Classes.php on line 157

this is the code it is referring to

class PartTimeTeacher extends Teacher {
  Private $Hours;

  public function setHours($h){
     $this->Hours = $h;
   }
   public function getHours(){
     return $this->Hours;
   }
}

Line 157 is the last bracket, I have tried changing the 'include' to 'Require_once()' but it didn't make a difference so will not run, I don't know what to do to get it to work?

pip
  • 31
  • 5
  • Read and understand [the duplicate](https://stackoverflow.com/a/13879461/476). Fix your code up accordingly as best you can. Show us the fixed up version **and a minimal example that will reproduce this error.** With what we're seeing right now we do not have enough information to diagnose the issue for sure. Maybe you really are declaring two classes called `PartTimeTeacher`. – deceze Feb 07 '18 at 09:22
  • i do call the 'classes' file in the 'functions' file, would that count as a duplicated class? – pip Feb 07 '18 at 09:24
  • Try using `include_once` – Nico Haase Feb 07 '18 at 09:25
  • In both files or just one? – pip Feb 07 '18 at 09:29
  • An `include` will definitely load the file. If you do an `include_once` first and then another `include`, the file will be loaded twice. You should only ever `require_once` (I cannot not think of a case where `include*` would be more useful). – deceze Feb 07 '18 at 09:30
  • I have changed the include to be 'include_once' and it now has the error ' Undefined property' as it can't call the class when the file is only included once – pip Feb 07 '18 at 09:31

0 Answers0