I have had some really strange errors here with php today.
I’ve written a little class for A/B Testing and wanted to create a new instance in a php document of mine:
if(!class_exists('ab_tester')) include('../lib/php/ab_tester.php');
$ab = new ab_tester($user['id']);
One would think this should do the trick, but php says:
Fatal error: Cannot redeclare class ab_tester in [PATH_TO_PHP]ab_tester.php on line 10
Why does this happen?
Note: Line 10 of the ab_tester.php looks like this:
class ab_tester {
If I leave the include line out, creating a new instance of ab_tester, it spits out:
Fatal error: Class 'ab_tester' not found in [PATH_TO_PHP]returning.php on line 25
What do I do now? If I try to import it, it’s already there and if I don’t, its missing.
And what do the first 9 lines of code in ab_tester.php contain?
I bet that there is another
class ab_testerthere (or in an include, anyway)EDIT:
Another possible explanation is that you are doing a second include of
ab_tester.phplater on the code ofreturning.php. So even if you useinclude_oncein this particular line, the second call is still just aninclude…