Code igniter : Why we call the parent constructor? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Code igniter : Why we call the parent constructor?

class Test extends CI_Model { function __contruct() { parent::__construct(); } } =>So, my question is, why do we need to call the parent class constructor?... As we are already extending Model class .So, all the properties and methods will be available... so why we need to do so?

10th May 2018, 5:56 AM
Saurav Kumar
Saurav Kumar - avatar
1 Answer
+ 1
Because when you declare a constructor you can also choose to override the Model one. So when you choose not to do so, the program has to know what constructor you will use then. You say that to the program by saying: hey i use the constructor of my parentclass! That's at least the case for Java, but I guess it applies for PHP as well.
10th May 2018, 6:03 AM
***
*** - avatar