Your code looks like it's using the PHP4 syntax for constructors. You should switch to the PHP5 syntax PHP4: class MyClassName { function MyClassName() {...} //constructor. } PHP5: class MyClassName { function __construct() {...} //constructor.
} You can then call the constructor of a parent class by calling parent::__constructor() from within the child class's constructor() method: class MyClassName extends SomeOtherClass { function __construct() { //...code here runs before the parent constructor. Parent::__construct(); //...code here runs after the parent constructor. } }.
Your code looks like it's using the PHP4 syntax for constructors. You should switch to the PHP5 syntax. PHP4: class MyClassName { function MyClassName() {...} //constructor.
} PHP5: class MyClassName { function __construct() {...} //constructor. } You can then call the constructor of a parent class by calling parent::__constructor(); from within the child class's __constructor() method: class MyClassName extends SomeOtherClass { function __construct() { //...code here runs before the parent constructor. Parent::__construct(); //...code here runs after the parent constructor.
} }.
1 Upgrade to CI 2.0 for proper use of __construct() all the way through or some versions of PHP will not handle the constructors properly. Some versions can have __construct() map to PHP4-style Controller, but CI 2.0 just removes all PHP 4 style constructors. – Phil Sturgeon Feb 3 at 11:22.
For PHP in general the parent constructor is not called default if the child has a constructor. Constructors. It can be called using parent::_construct(); If you're using php 5+ you should go with the new recommended style of using function __construct() instead of the old style with a function named the same as a class.As for CI-specific stuff I can't help you, sorry!
If you do not override __construct() in MY_Controller then Controller's __construct() will get run. If you override it and then called parent::__construct() then it will run your own and the parent's. So if you wanted it to run the parent's and your own you would do this class MY_Controller extends Controller { var $data = array(); function __construct() { parent::__construct(); // Your code here } }.
Yes, the parent constructor it is always called (you may want to rewrite them as __construct() however, thinking also at codeigniter 2.0 ). If you really are in doubt toss in it an echo and see it for yourself. Also the $this->data part is correct to me.
You are right in your affirmations about the data array contents. In you code you wrote: function MY_Controller() { parent::Controller(); so the parents's class constructor is being called. There are lots of comments about PHP4 and PHP5 syntax, but basically everithing is ok.In your question you wrote that if the controller class extending the MY_Controller is instantiated that is not correct.
The instance is an object of class api_controller, calling the MY_Controller constructor is made using the same object. That is not the same, that is basic for polimorphism.
But I would like to show the power of parent::__construct for use with PHP's OOP polymorphic behavior (you'll see what this is very quickly). In my example, I have created a fairly robust base class that does everything that all subclasses need to do. Here's the base class def.
* subclass extensions need to use. * define the sorting rules - we will sort all Animals by name. * a String representation for all Animals.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.