Welcome Guest, Not a member yet? Register   Sign In
calling parent constructors
#1

[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?
#2

[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.




Theme © iAndrew 2016 - Forum software by © MyBB