Search code examples
phpnamespacesclassnotfound

Class not found error, is namespace usage wrong?


I got a folder structure similar to:

top
 - folder1
    - file1
 - folder2
    - file2

Now when I write $var = new \Namesp\class2 in file1, it tells me that the Class class2 was not found.

file1:

$var = new \Namesp\class2;
...

file2:

namespace Namesp;
class class2 { ... }

Solution

  • I found my mistake: Due to me never working without an autoloader before, I simply forgot to include the needed files before accessing them.

    After doing that, everything worked as expected. Thank you @Mark Baker