I'm working on a project which has two components:

1) One is the CodeIgniter framework in which I'll be building all of my custom code.

2) The other is Amazon's PHP SDK libraries for MWS API.

The issue is, both my CodeIgniter code and Amazon's SDK require their own autoload().

Amazon's SDK is also further split up into 3-4 components, each of them has their own autoload function, so if you want to work with Products' SDK, and then Reports SDK in the same session, you would run into the already defined autoload function.

For this reason, I'm thinking about setting up a web services system for communication between my own code and Amazon's SDK files, even though they're on the same server, but at least this way the naming conflicts can be avoided. I.e I'll send a HTTP request to a file outside CodeIgniter, which will deal with Amazon's SDK, and return a response in JSON or XML.

I don't think namespaces are an option since I don't want to go through each file/class in the SDK and add namespace statements.

My question is, are there any performance issues with this method that I should be aware of? And is there any way apart from namespaces that this method could be avoided?

  • I was under the impression that if libraries use SPL autoloaders, that several can co-exist together. Do they all really use the legacy __autoload() function? I should think that if two Amazon packages won't work well together for this reason, that someone would have raised it as a bug/improvement ticket already. – halfer Jan 14 '13 at 11:13
  • @halfer I've downloaded the latest SDKS and yep, they do use the legacy __autoload – Click Upvote Jan 14 '13 at 11:33
  • How odd that you can't use several together! Well, I'd raise a ticket about this, if one does not exist already. Another approach: is it possible to not load the autoloaders for Amazon and CI, and to write your own to glue it all together? – halfer Jan 14 '13 at 11:50
  • @halfer Thanks for the help. No, I think that will lead to a lot of hair pulling because the SDK autoloaders are doing some tricky stuff with the include paths. However, thanks for alerting me about SPL autoloading, that might solve my problem. If you'd like to post an answer showing quickly how to use SPL autoloaders, I'll accept it. – Click Upvote Jan 14 '13 at 11:53
  • Happy for @lbmurai to have it :) – halfer Jan 14 '13 at 18:29

Just copy their autoloader functions to a separate file, rename them, and hook them up with spl_autoload_register thus:

function loadFrameworkOne($name) {
    // contents of __autoload from framework one.
function loadFrameworkTwo($name) {
    // contents of __autoload from framework two.

This is quick, dirty and off the top of my head ;)

Your Answer

