示例#1
0
<?php

class Foo
{
    public $result;
    protected $message;
    protected $level;
    function __construct($message = 'Nothing to say', $level = E_USER_NOTICE)
    {
        $this->message = $message;
        $this->level = $level;
    }
    function raiseError()
    {
        trigger_error($this->message, $this->level);
    }
    function something()
    {
        $this->result .= ' do intermadiate result';
        return $this;
    }
    function somethingelse()
    {
        $this->result .= ' do final result';
        return $this;
    }
}
$foo = new Foo();
echo $foo->something()->somethingelse()->result;
$foo->raiseError();
示例#2
0
}
class Foo
{
    public function something()
    {
        throw new AnotherException();
    }
    public function somethingElse()
    {
        throw new MyException();
    }
}
$a = new Foo();
try {
    try {
        $a->something();
    } catch (AnotherException $e) {
        $a->somethingElse();
    } catch (MyException $e) {
        print "Caught Exception";
    }
} catch (Exception $e) {
    print "Didn't catch the Exception!";
}
//Caso curioso:
/*
try {
    throw new \Exception();
} catch (\OdinException $e) {

} catch (\Exception $e) {