Jump to content

Can't Find an Autoloaded Helper Class


nwcasebolt

Recommended Posts

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.

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated