CakePHP doesn’t like autoload() with vendor app import!

So, it would seem that if you decide that you want your vendor plugin to work nicely with cake, by having it conform to Pear folder directory structure and naming convention, and then right yourself a nice autoload() function to register with php (via spl_autoload_register()), you CANNOT use the App::import alongside this.
Why? Because Cake’s lovely App::import does a require() not a require_once()… Go figure!

So here is the problem:
You have App::import()’d your vendor plugin. It registers itself as an autoloader.
You have your 2nd vendor plugin, (which conforms to a Pear style structure also).
You explicitly App::import(’vendor’,'2nd item’,array(’file’=>’path/to/vendor/file.php’));
Cake has a fit and dies saying you “cannot redeclare “.
Brilliant Cake well done! Another reason to use Zend Framework…

As a solution I have altered the cake source code to make sure the require() is in fact a require_once(). I have yet to see the impact of such a change on any other import()’s. See below for alteration:
File: cake/libs/configure.php
Line: 975
Previous: “require($file);”
Change: “require_once($file);”

Leave a Reply