Skip to content

Instantly share code, notes, and snippets.

@Stelian
Created September 19, 2012 10:29
Show Gist options
  • Save Stelian/3748899 to your computer and use it in GitHub Desktop.
Save Stelian/3748899 to your computer and use it in GitHub Desktop.
/** Instantiating a class **/
function __autoload($name) {
echo "Want to load $name.\n";
throw new Exception("Unable to load $name. \n");
}
try {
$obj = new NonLoadableClass();
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
Output:
Want to load NonLoadableClass.
Unable to load NonLoadableClass.
/** Static call **/
function __autoload($name) {
echo "Want to load $name.\n";
throw new Exception("Unable to load $name.");
}
try {
$obj = NonLoadableClass::a();
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
Output:
Want to load NonLoadableClass.
Fatal error: Class 'NonLoadableClass' not found in /var/www/test/a.php on line 11 Call Stack: 0.0002 641792 1. {main}() /var/www/test/a.php:0
PHP Version 5.3.10-1ubuntu3.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment