CodeIgniter Forums
Call to undefined (helper) function - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Call to undefined (helper) function (/showthread.php?tid=76129)



Call to undefined (helper) function - Gary - 04-15-2020

Hello,

I have a helper function which is loaded in BaseController.php in the normal way with protected $helpers = ['myhelper,].

It is used to add some text details to a view and has been faithfully working without a problem until recently…

Now, when I have any exception thrown, for example:  CodeIgniter\Images\Exceptions\ImageException: The supplied file is not a supported image type (though, any exception/error condition appears to cause the same effect), I receive the following (code terminating) response on any subsequent interaction with the server:  Error: Call to undefined function myhelperFunction() (which is the previously well-behaved helper function inside the view page).

This error remains until I force a cache-refreshing re-load of the page.

I would try to invoke the call with a fully qualified path or namespace, but because it is a helper function, it isn’t namespaced and I’m not sure how to call it using a path, and then the .php file’s internal function name?

It appears as though the framework loses the current BaseController’s setting/environmentsettings?!?

Is this normal?  Why is it happening?  What am I doing wrong?

Thanks.


RE: Call to undefined (helper) function - InsiteFX - 04-15-2020

Did you change any of your code? Helpers belong to the App namespace.

I would double check your coding to see if something is causing this to happen.


RE: Call to undefined (helper) function - Gary - 04-15-2020

Thanks for the suggestions InsiteFX, and the info that helpers are in the App namespace (which seems sensible, but I'd not thought of).

I have been messing around with some (seemingly unrelated) image-processing stuff, and a bit of CSRF experimentation (which may be more likely the cause (?))...

As an initial experiment, I did try to add a path to my view insertion: <?=\App\myhelperFunction();?>

This results in: Error: Call to undefined function App\myhelperFunction()