michaelbeersnl
Gebruiker
- Lid geworden
- 30 nov 2011
- Berichten
- 57
Probeer het is zonder __autoload() want na mijn ervaringen werkt deze functie niet goed
Anders kun je dit ook nog proberen... ik heb het niet getest maar het zal vast wel werken
Verder zou ik de classes aanroepen met een exception...
Overige opmerkingen:
- Begin een classe altijd met een hoofdletter net als elk nieuwe woord (camel casing).
- Zorg dat je classe naam gelijk is aan je bestandsnaam
- Gebruik comments
Anders kun je dit ook nog proberen... ik heb het niet getest maar het zal vast wel werken
Verder zou ik de classes aanroepen met een exception...
PHP:
<?php
/**
* Load classes using the __autoload() magic function in php
*
* @param mixed $class The class name
*/
function __autoload($class)
{
//canonicalize the absolute pathname
$path = realpath('libs/' . $class .'.php');
//check if the file exists
//else throw a new exception
if (file_exists($path))
{
//file exists
required_once($path);
} else
{
//file does not exists, throw exception
throw new Exception('Unable to load <strong>' . $path . '</strong>');
}
}
//try to do the email action
//else throw exception
try
{
$email = new emailer();
..
} catch(Exception $e)
{
echo $e->getMessage() . "\n";
}
?>
Overige opmerkingen:
- Begin een classe altijd met een hoofdletter net als elk nieuwe woord (camel casing).
- Zorg dat je classe naam gelijk is aan je bestandsnaam
- Gebruik comments
