PHP Class Redefinition Clarification
I have a LinkedIn API class that I'v开发者_如何学Pythone written for PHP that makes use of a third-party stand-alone OAuth class, not the possibly installed PECL PHP OAuth extension. I've designed it this way to allow the many users don't have the ability/access to install the PECL extension to make the needed OAuth calls.
So, for PHP installs with no PECL extension installed, all works perfectly. The issue is on server's that DO have the PECL extension installed... instantiating the third-party OAuth class gives re-definition errors, as both the PECL extension and the third-party class have called their classes 'OAuth'.
It would be great to have my class flexible enough to support both situations, but of course the two conflicting classes have different method names, etc.
I know the simple answer is to advise people that my library is ONLY for those situations on the server where you don't have the PECL extension installed, but I am wondering if there are any other solutions.
From the sound of it, the PECL class and yours are not really compatible, so the obvious solution would be to rename yours or move it into a separate Namespace (PHP >= 5.3 only!).
If they are supposed to be compatible, you could also include your OAuth include only if the PECL class is not defined:
if (!class_exists("OAuth"))
require "/path/to/your/oauth.php";
Don't know if this would work but maybe
require_once("/path/to/your/oauth.php");
精彩评论