stripe/stripe-php — pull request #22 by scottlangendyk (2012-11-07 20:40:36+00:00)
Title: Fix fatal error when using an autoloader

I was having a problem with stripe-php, where if I passed an API Key directly to one of the "constructor" methods PHP experienced a fatal error, with the message "Cannot redeclare class Stripe_Util_Set".

This only happens when using an autoloader like the one composer generates, because every time an object uses the Stripe class, the autoloader includes the Stripe.php file which not only contains the class definition but also includes all the other class files itself. Of course since the autoloader would have already included at least one of those class files (the class of the object using the Stripe class), the class gets declared twice and we end up with that fatal error.

I've done two things. First was I changed all the require statements in the main Stripe.php file to use require_once. Secondly I split the actual Stripe class out to it's own file, so that way the autoloader can still only load class files as they're needed.

I didn't add a test to the test suite, because the current test suite does not use an autoloader.