Cannot redeclare class require_once

Problem

I’m using classes and making each class a file. when I’m including dependet classess, I use require_once to avoid multiple declarations – yet I get a Fatal error: Cannot redeclare class…

 

Solution

Make sure all files that require the class have require_once and also make sure that the path that is required is the same case in all situations.  For example, my problem was that I was including a “/Users/name/xxx.php” and “/users/name/xxx.php”.  These paths are different and so PHP includes both of these.

 

keywords: Cannot redeclare class require_once
source: http://bytes.com/topic/php/answers/461064-require_once-doesnt-work-cannot-redeclare-class

 

Tagged with: ,

Leave a Reply