多分に漏れず、初心者がはまりそうな部分を書いておきます。
__constructによるコンストラクタの継承による不具合発生。
PHP4までの親コンストラクタの継承は「this->親クラス名」で継承されていましたが__constructで書こうとすると思わぬエラーが出ることがあります。 Smartyの拡張セットアップも「this->Smarty();」となっていますね。
http://www.smarty.net/docsv2/ja/installing.smarty.extended.tpl
これを「parent::__construct()」で継承するまではいいのですが、親コンストラクタのほうを__constructに変更するとエラーが出ます。
- class Test {
- public function __construct() {
- echo "Testコンストラクタです\n";
- }
- }
- class TestChild extends Test {
- public function __construct() {
- $this->Test(); //エラー
- echo "TestChildのコンストラクタです\n";
- }
- }
冷静に考えれば$thisで親コンストラクタを呼び出すこと自体変なので、新しい親コンストラクタは「parent::__construct()」で呼び出してください。
- class Test {
- public function __construct() {
- echo "Testコンストラクタです\n";
- }
- /*
- //古い書き方であっても大丈夫です
- public function Test() {
- echo "Testオブジェクトを生成します\n";
- }
- */
- }
- class TestChild extends Test {
- public function __construct() {
- parent::__construct();
- echo "TestChildのコンストラクタです\n";
- }
- }
であれば親が古い書き方であってもエラーは出ません。