PHPのメソッドチェーン

jQueryを使っているのですが、メソッドチェーンって便利ですね。

ってことで、PHPメソッドチェーンなのですが、・・・コンストラクタがなぁ。。。 [php]<?php

class Hoge { function Hoge() { } function & a() { echo 'a'; return $this; } function & b($str) { echo 'b' . $str; return $this; } }

$h = new Hoge(); $h -> a() -> b('hello');

// output, 'abhello' [/php]