PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
class Boot
{
public function __construct()
{
set_exception_handler('Boot::exception');
$this->doSomeStuff();
}
public function doSomeStuff()
{
throw new Exception('throwing some exception.');
}
public static function exception($e)
{
global $boot;
// $boot = $GLOBALS['boot'];
$boot->printException($e);
}
public function printException($e)
{
echo $e->getMessage();
}
}
$boot = new Boot();
?>
Two things I think. First, your object constructor is calling doSomeStuff() which is throwing an exception, so the object is not being created (you should be able to verify this with var_dump). Try moving the exception out of the constructor and into a method thats called on the object after its been created.
Second, and probably the reason for your problem, the method printException is not a static method so it's not accessible by Boot::exception(). Easiest solution is to add the static keyword to that function.