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 {
}

?>

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.