List Info

Thread: note 77471 added to language.oop5.autoload




note 77471 added to language.oop5.autoload
user name
2007-08-30 15:16:22
If you would like __autoload to throw an exception when the
class cannot be loaded instead of causing a fatal error,
consider this:

<?php
function __autoload ($className)
{
    $fileName = str_replace('_', DIRECTORY_SEPARATOR,
$className) . '.php';
    $status = (include_once $fileName);
        
    if ($status === false) {
        eval(sprintf('class %s {func' . 'tion
__construct(){throw new
Project_Exception_AutoLoad("%s");}}', $className,
$className));
    }   
}

$pageController = 'Project_My_Class'; //
"Project/My/Class.php"

try {
  $obj = new $pageController();
} catch (Project_Exception_AutoLoad $e) {
    header('HTTP/1.0 404 Not Found');
    printf('<h1>Not Found</h1><p>The
requested page %s was not found on this
server.</p><hr /><em>$id$</em>',
$_SERVER['REQUEST_URI']);
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 71.42.115.242
----
Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php
Edit        -- https://master
.php.net/note/edit/77471
Del: integrated  -- h
ttps://master.php.net/note/delete/77471/integrated
Del: useless     -- http
s://master.php.net/note/delete/77471/useless
Del: bad code    -- htt
ps://master.php.net/note/delete/77471/bad+code
Del: spam        -- https:/
/master.php.net/note/delete/77471/spam
Del: non-english -- 
https://master.php.net/note/delete/77471/non-english
Del: in docs     -- http
s://master.php.net/note/delete/77471/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/77471
Reject      -- https://mast
er.php.net/note/reject/77471
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )