0

I'm adding a 3rd party library (Hybrid Auth) to my zend project. The main class called is hybrid_auth. I'm assuming that having an underscore in the class name with throw an error in zend? Should I rename this class throughout the library or would it be better to create my own autoloader?

Forgive the brevity, I'm on my phone and will try to update later.

Thanks.

dev-null
  • 551
  • 1
  • 4
  • 13
  • Try it. Did it work? If it did, don't worry. If it didn't find out why. (I would expect that an underscore is valid in a class name because an underscore is valid in PHP identifiers, but I don't use Zend .. or PHP.) –  Sep 05 '12 at 19:01

1 Answers1

2

It won't throw an error, per se. Underscores in classnames are perfectly fine.

But the default autoloader will try to find the class hybrid_auth on your include_path in the file hybrid/auth.php.

You can either:

  1. Do a manual include before referencing the class so that autoloading doesn't kick in

  2. Write a custom autoloader for this class - and any others like it - and push that autoloader onto the Zend_Loader_Autoloader stack.

  3. Rename the class and/or filename to be PSR-0-compliant so the standard autoloader is happy with it.

Personally, I'd go with (2): write your own autoloader. I hate to monkey-patch 3rd-party library code because subsequent lib updates overwrite my hack.

For writing your own autoloaders, take a look at this.

Community
  • 1
  • 1
David Weinraub
  • 14,144
  • 4
  • 42
  • 64
  • 1
    Brilliant, I'll write my own autoloader. I have had it working by changing the names of the classes but I was worried that somewhere down the line it would all come back to haunt me. – dev-null Sep 05 '12 at 19:52
  • For anyone else who happens upon this: I made a mistake. I was trying to add my own suffix to the autoloader and this was making everything go belly up. The download from Hybridauth is already set out in folder 'Hybrid' containing file Auth.php with the class Hybrid_Auth, so as long as you register 'Hybrid_' in your autoloader then all will be well. – dev-null Sep 09 '12 at 19:48
  • Just beware of upper/lower case: Original question references classname as `hybrid_auth`, comment above references it as `Hybrid_Auth`. Glad that you got it working. Cheers! – David Weinraub Sep 10 '12 at 02:32