Ticket #36 (closed enhancement: fixed)

Opened 21 months ago

Last modified 13 months ago

Use spl_autoload_register instead of autoload

Reported by: kmeirlaen Owned by: somebody
Priority: important Milestone: 1.1
Component: QForms Version:
Keywords: Cc:

Description

autoload can step on toes if any other code tries to register an auto-loader.
Instead, we should be using http://ca.php.net/function.spl_autoload_register

By Ryan Peters on Nov 03, 2008 @ 07:49pm *
http://qcodo.com/downloads/item.php/213 may be useful

Attachments

spl_autoload_register.patch (2.1 kB) - added by basilieus 15 months ago.

Change History

Changed 16 months ago by cdhamm

I ran into this issue when trying to convert the ORM to a plugin based system. As a side affect, my code would fix this issue, see:

http://trac.qcu.be/projects/qcubed/ticket/206

Changed 16 months ago by alex94040

Thanks a bunch for your contribution! Could you be so kind and create an SVN .patch file, so that we're able to review your work easily?

Changed 15 months ago by basilieus

I've made one... it doesn't change much, and I'm not sure if this will effect how we do plugins etc, but this is a simple direct approach that has worked for me. see below:

Changed 15 months ago by basilieus

Changed 15 months ago by VexedPanda

Are you thinking we could just insist that every plugin define their own autoloader to ensure that the app knows about plugin classes?
We still run into the problem of setting those autoloaders without doing a recursive search of plugin folders, so I think the proposed ini/xml files parsed at design time is the best approach we've come up with.

That said, this change should make QCubed much more viable for inclusion in other applications / frameworks. Thank you. :)

Changed 15 months ago by basilieus

Vex: I'm not sure what I was thinking about plugins.

Changed 15 months ago by basilieus

Also, I might create a custom AutoLoader? class that we can expound upon and make things a bit easier and more customizable.

The patch above is a quick easy fix.

Changed 15 months ago by marcosdsanchez

I agree with Basilieus on creating a custom Autoloader class.

this is a quick draft of how it could be:

<?php

abstract class QAutoloadBase extends QBaseClass{

       
        public static function Autoload($strClassName) {
            if (array_key_exists(strtolower($strClassName), QApplication::$ClassFile)) {
                require(QApplication::$ClassFile[strtolower($strClassName)]);
                return true;
            }
        }

        public static function RegisterAutoload(){
            spl_autoload_register(array('QAutoloadBase','Autoload'));
        }

}
?>

Changed 15 months ago by VexedPanda

I wonder if we can take advice from anything in here:
http://devzone.zend.com/article/4525-Developing-a-Comprehensive-Autoloader

Changed 13 months ago by MikeHostetler

  • milestone changed from 1.1 to 1.2

Changed 13 months ago by VexedPanda

  • status changed from new to in_QA

I vote we commit basilieus's patch to 1.1, it looks clean to me, and solves the problem.

Changed 13 months ago by alex94040

  • milestone changed from 1.2 to 1.1

I think this actually has been checked in already - at least, prepend.inc.php already has an spl_autoload_register() call.

Changed 13 months ago by VexedPanda

Cool. Sholud we close this ticket then, or is there more here we should be looking at?

Changed 13 months ago by MikeHostetler

  • status changed from in_QA to closed
  • resolution set to fixed

Closing this ticket.

Note: See TracTickets for help on using tickets.