XOOPSCubeLegacy​/CookBook

PHP class constructors anchor.png

If you use other languages --- C++, Java and etc, you must pay attention to the spec of PHP class. In PHP, Sub class constructors don't call their base class constructors automatically. So you need to call them in the constructor. You may write it as the following;


class Base
{
  function Base()
  {
  }
}

function SubClass extends Base
{
  function SubClass
  {
    parent::SubClass();
  }
}

Under PHP language spec, you may write the initializer anywhere. But, you should write it in the head part of the constructor. That's accords with other languages.

Even if the base class constructor is an empty, you must do it. Because the base class constructor may be modified in the future.

Page Top

Note anchor.png

A sub class which doesn't call its base class constructor caused troubles actually. Click here to read about it.


Front page   Freeze Diff Backup Copy Rename ReloadPrint View   New Page Page list Search Recent changes   Help   RSS of recent changes (RSS 1.0) RSS of recent changes (RSS 2.0) RSS of recent changes (RSS Atom) Powered by xpWiki
Counter: 13963, today: 1, yesterday: 1
Princeps date: 2007-04-23 (Mon) 20:24:16
Last-modified: 2007-04-23 (Mon) 20:24:16 (JST) (4416d) by Anonymous

Welcome | News | Overview | Documentation | Forum | Tutorialstop
Brasilian | French | German | Greek | Japanese | Korean | Russian | T-Chinese
Powered by XOOPS Cube 2001-2011 The XOOPS Cube Project