Use Classname () or __construct () as a constructor in CodeIgniter?

Should I use Classname () or __construct () as a constructor in CodeIgniter?

both work that i should use?

+6
php codeigniter
source share
2 answers

Classname() is the old way (i.e. the PHP 4 path).

__construct() is a new (i.e. PHP 5) way.

You should use the second if your application is written using PHP 5 - and you should write your applications with PHP 5 in mind!


See the Constructors and Destructors section in the manual that says (citation):

For backward compatibility, if PHP 5 cannot find the __construct() function for this class, it will look for the old-style constructor function, the class name.

+9
source share

ClassName() and __construct() are the same as the constructor.

__construct() function is the most useful comparison with ClassName() , because when you change your ClassName() , you must change the name of your constructor, but you do not need to change __construct() , and also use it in the child class.

0
source share

All Articles