Issue including file in php gives error whether I include file or not

FROM

include('basemodel.php');

      

I get

Fatal error: Class 'BaseModel' not found in C: \ xampp \ htdocs \ allsides \ account \ model.php on line 2

Without

include('basemodel.php');

      

I get

Fatal error: Cannot override BaseModel class in C: \ xampp \ htdocs \ allsides \ others \ basemodel.php on line 2

0


a source to share


5 answers


Never, never, never use include or require. Use include_once or require_once. There are a few minor exceptions to this rule. But most of the time, when your code says include or require, change it to include_once or require_once.



(Template engines and similar code in code oddities and eval workarounds sometimes need non-_once versions, but that's not what you do.)

0


a source


Try:

require_once ("basemodel.php");



===

Edit: wait - what other files are you including?

0


a source


For me, the error says exactly what it says!

What happens if you rename C: \ xampp \ htdocs \ allsides \ others \ basemodel.php to C: \ xampp \ htdocs \ allsides \ others \ basemodel1.php (including class definition)

It looks like you have two files with the same name.

0


a source


Somehow you have two declarations of the "BaseModel" class. But since this only happens when you include your file, I suggest you better examine this spesific file.

Maybe the BaseModel file contains some other files that include the BaseModel again? Or maybe you are trying to declare the BaseModel class twice in the file?

NB: I would recommend that you always use include_once () or require_once () instead of include / require!

0


a source


APC (caching engine) sometimes does this for me. If you are using it, try clearing the opcode cache:

apc_clear_cache("user"); // user cache
apc_clear_cache(); // system cache

      

0


a source







All Articles