Last Updated: February 25, 2016
·
413
· rezigned

Be careful with require_once

Problem

You encounter this kind of error "Cannot redeclare class ..." even though you already used the require_once to make sure that you include the file only once. What!?

Solution

The problem is, there's a chance that the path that being included has different character cases from the physical file on the system. (Due to case sensitivity)

For example (The actual file is 'App/File.php')

<?php
 require_once 'App/file.php';

 # if you somehow run this require_once again. It will shows the error above
 require_once 'App/file.php'

So, make sure you have the correct file name before execute the require_once