Jump to content

__autoload displays correct file but does not include it properly.


PC Nerd

Recommended Posts

Hi,

I've written this small __autoload for my page, and it's echoing the correct file out, however I get the "Class blah not defined" in my script.  I've root (/) in the filenames is the root of the installation, and htdocs i the only web accessable folder.

 

From the echo below, I get: "../system/classes/UI.class.php", which definately exists.  I'm stumped.

 

Thanks for any help.

PC_Nerd

 

/htdocs/index.php

<?php
function __autoload ($className) {
    $filename =$className.'.class.php';
    $filename = str_replace('\\', "/", $filename);
    if ( preg_match( '/[\w\d\.]+\.php$/', $filename, $matches) ) {
        $filename=SYSTEM_DIR."classes/".$matches[0];
        if(file_exists($filename)) {
            require_once $filename;
            return;
        }
        else {
            echo "The file: ".$filename." -> was not found.\n";
        }
    }
    throw new Exception("Required file was not found: ".$filename." - Class not loaded");
}
?>

 

/system/classes/UI.class.php

<?php

namespace framework\ui;
class UI extends framework\system\Singleton {
}

?>

Solved  (myself)

Somehow its started working. I looked into how the names were getting passed and I think its to do with this being the second __autorun call, based on another dependency...  I had named namespaces without the leading \ and thus I was attempting to access \framework\system\framwork\ui\UI  etc....    just like a filysystem only crunchy!

 

Thanks :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.