Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal Error. Uncaught error: Class 'CI_Controller' not found #6290

Open
cuartas15 opened this issue Jul 24, 2024 · 5 comments
Open

Fatal Error. Uncaught error: Class 'CI_Controller' not found #6290

cuartas15 opened this issue Jul 24, 2024 · 5 comments

Comments

@cuartas15
Copy link

So this is a kinda old project running CI3 and we're facing this issue. It's very sporadic, it seems like it happens when requesting Ajax routes and the temporary fix testers have found is to "Clear the browser's cache".

From what I can see, people that faced this exact error and reported on StackOverflow have so many different causes too far and between, so I couldn't pinpoint the exact issue.

Of course we don't touch core files, just extend from them in our own controllers, and the fact that it happens at random doesn't help to the issue.

This is a screenshot of what we see in one of the Ajax responses:

4hQVhnNL

This stack trace points to this file called MY_Exceptions.php which has this code, reading another issue report here I kinda thought it was because at this point in the lifecycle CI_Controller wasn't loaded, but this is an Ajax call though, wouldn't the Core components be up even before my code is executed at that point?:

GssO9nkQ

Again, let me emphasize that this doesn't happen all the time with all the existing Ajax requests, nor consistently through all the user machines and browsers, it just happens, a browse cache clear and it's working as intended again.

Can you people help me try to find the cause of this issue? thanks in advance

@jamieburchell
Copy link
Contributor

jamieburchell commented Aug 2, 2024

The error causing this must be happening early in your application, before CI_Controller has been included. Due to the way in which PHP works, the get_instance function will be available, but the controller class may not have been required/included yet.
If you remove the code that is calling get_instance, at least you will be able to ascertain what the actual cause of the error is. You cannot rely on CI_Controller being available here - you could check for it.

This isn't a bug in CI as far as I can see, so should probably be a Stack Overflow / forum question.

@cuartas15
Copy link
Author

The error causing this must be happening early in your application, before CI_Controller has been included. Due to the way in which PHP works, the get_instance function will be available, but the controller class may not have been required/included yet. If you remove the code that is calling get_instance, at least you will be able to ascertain what the actual cause of the error is. You cannot rely on CI_Controller being available here - you could check for it.

This isn't a bug in CI as far as I can see, so should probably be a Stack Overflow / forum question.

You and I know, this will never be answered on stack overflow, actually I came here after radio silence in there.
I tried something, which was removing the file MY_Exception, thinking it wasn't being really used/referenced anywhere and it was just being loaded as a result of a line batch loading the files of a folder in codeigniter, also, that it seemed to be made by one of the previous developers of this project.
Turns out it's absolutely needed, any Exception thrown in the project goes through this file, so everything was breaking in it's absence.
Now, that got me thinking, this CI error is happening on the development environment after any exception is thrown out? maybe? that would've been worrysome because that would compromise the entire try - catch structure we have in the code, fortunatelly it wasn't the case, I forced a condition to throw an Exception and it worked just fine.
But that puts us to the beginning, the only thing we know is that this is a random thing we can't catch just yet, I'll even say more, our tester said last week he got the CI error in another random place, but a couple hours later when I told him to check something for me, he went to test it again and it wasn't happening anymore, he didn't even need to clear cache.

This is a really weird bug tbh

@jamieburchell
Copy link
Contributor

jamieburchell commented Aug 5, 2024

You might have better luck on the CodeIgniter forum if SO isn't helping.

The "MY_" classes are override classes (by default) in CI. They will be loaded instead of the "CI_" classes.

I still believe your exception is happening before the CI_Controller class is included/required in line 308 above.

For debug purposes:

remove the code that is calling get_instance, at least you will be able to ascertain what the actual cause of the error is.

@cuartas15
Copy link
Author

cuartas15 commented Aug 5, 2024

You might have better luck on the CodeIgniter forum if SO isn't helping.

The "MY_" classes are override classes (by default) in CI. They will be loaded instead of the "CI_" classes.

I still believe your exception is happening before the CI_Controller class is included/required in line 308 above.

For debug purposes:

remove the code that is calling get_instance, at least you will be able to ascertain what the actual cause of the error is.

But If I remove that line that means I would need to also remove the line that's refreching the csrf token, wouldn't that just make the code unable to keep the token up to date?

EDIT: I posted it in the CI forums as well

@jamieburchell
Copy link
Contributor

jamieburchell commented Aug 5, 2024

I literally mean remove that line and print out the exception that you have to work out what is causing it, rather than trying to do something with CI_Controller which isn't available to you at the point your exception is happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants