![]() |
calling parent constructors - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: calling parent constructors (/showthread.php?tid=30465) |
calling parent constructors - El Forum - 05-15-2010 [eluser]skaterdav85[/eluser] When creating a new model or controller, I noticed that you don't have to call the parent class constructor. However, I just bought a new CI book called CodeIgniter 1.7 Professional Development, and all their examples in the first chapter (which introduces the MVC design pattern) call the parent class constructor for models and controllers. When is it necessary to do so? calling parent constructors - El Forum - 05-15-2010 [eluser]theprodigy[/eluser] I don't believe it is "necessary", but it is good practice. By default, if PHP does not find a constructor, it will look to the parent for one. The only time it is absolutely necessary for the php class to have a constructor is if you want something to happen when your class is instantiated, that differs from just calling the parent constructor. Other then that, it's not necessary, but like I said, it's just good practice. |