Autoload fails on install

jtsnow - January 15, 2009 - 08:50
Project:Autoload
Version:6.x-1.2
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

I am trying to use this for a module I'm developing. I was previously using my own autoloading method. Swapping in code using Autoload module instead of my method works great except when I do a fresh install of my module.

Upon installing my module, I get a "Fatal error: Class not found'. It seems as if the installer loads all the include files in my module's directory. It loads them in alphabetical order. This is a problem when, for example 'class_a.inc' is loaded before 'class_b.inc' and class_a extends class_b. PHP tries to use autoload_class() to load class_b, but is unable to do so. Apparently autoload_flush_caches() has not been called at this point.

I tried calling autoload_flush_caches() in my module's implementation of hook_install(), but that did not work.

Any suggestions?

#1

Crell - March 17, 2009 - 22:01

Unfortunately no. The installer doesn't call init hooks, I think, so the autoload isn't even registered yet. It also has not yet called your autoload hook implementation so it doesn't know about your classes anyway. Not sure what to do here. :-(

#2

KiamLaLuno - June 6, 2009 - 02:33
Assigned to:jtsnow» Anonymous

The installer doesn't call init hooks

A Drupal hook function is still a function that can be called from any functions, including any install, or update functions that a module could define.
The bigger problem, as I can see, it's the dependency between two classes, but I would expect the autoload function to be called for both the classes, which are not being found on any already loaded file.

#3

Crell - June 6, 2009 - 16:36

PHP's autoload capability will fire repeatedly as necessary if you have, say, multiple classes that inherit from each other. That is a non-issue.

 
 

Drupal is a registered trademark of Dries Buytaert.