nwcasebolt Posted February 5, 2020 Share Posted February 5, 2020 According to the Module Class Autoloading docs, I should be able to create a helper class in my Gateway module and inject it as needed, where needed. I have: created {install}/modules/gateways/coolmodule/lib/CoolClass.php, with namespace: WHMCS\Module\Gateway\Coolmodule; made sure the file is 644 and directories are 755 injected my class with: use WHMCS\Module\Gateway\Coolmodule\CoolClass; instantiated my object with: $cool = new CoolClass(); PHPStorm likes everything I've done, and I expect to get a CoolClass object with which I can do cool stuff. What I get instead is a 500 server error: PHP Fatal error: Uncaught Error: Class 'WHMCS\Module\Gateway\Coolmodule\CoolClass' not found I would appreciate any leads from anyone who's successfully created and autoloaded and injected a helper class, because nothing I've tried so far has worked. 0 Quote Link to comment Share on other sites More sharing options...
nwcasebolt Posted February 5, 2020 Author Share Posted February 5, 2020 Addendum: Part of the problem is certainly that the WHMCS constant itself is not defined. Is this a Composer issue? 0 Quote Link to comment Share on other sites More sharing options...
Grizzlyware Josh Posted February 7, 2020 Share Posted February 7, 2020 On 2/5/2020 at 10:17 PM, nwcasebolt said: According to the Module Class Autoloading docs, I should be able to create a helper class in my Gateway module and inject it as needed, where needed. I have: created {install}/modules/gateways/coolmodule/lib/CoolClass.php, with namespace: WHMCS\Module\Gateway\Coolmodule; made sure the file is 644 and directories are 755 injected my class with: use WHMCS\Module\Gateway\Coolmodule\CoolClass; instantiated my object with: $cool = new CoolClass(); PHPStorm likes everything I've done, and I expect to get a CoolClass object with which I can do cool stuff. What I get instead is a 500 server error: PHP Fatal error: Uncaught Error: Class 'WHMCS\Module\Gateway\Coolmodule\CoolClass' not found I would appreciate any leads from anyone who's successfully created and autoloaded and injected a helper class, because nothing I've tried so far has worked. Can you show where you are instantiating your CoolClass instance please? What you've shown so far looks like it should work, however I suspect you're calling it without first initialising WHMCS (and its autoloader). 0 Quote Link to comment Share on other sites More sharing options...
nwcasebolt Posted February 10, 2020 Author Share Posted February 10, 2020 On 2/7/2020 at 2:19 PM, Grizzlyware Josh said: Can you show where you are instantiating your CoolClass instance please? What you've shown so far looks like it should work, however I suspect you're calling it without first initialising WHMCS (and its autoloader). Thanks, Josh. Oddly enough, I got this working by both (1) using the namespace and (2) requiring my class file. If I omitted either of those two steps, then I couldn't use my class. But, to answer your question directly, I built the class in our custom gateway module, within the module's lib folder; and I instantiate the instance from the gateway module file (not the callback ). That's what I found odd, because I think WHMCS should be initialized and running just fine by the time I hit the gateway. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.