Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between __construct() and init()

I was wondering what is the difference between __construct() and init() functions in a PHP application, more particularly in a Zend Framework application.

like image 905
tom Avatar asked Sep 19 '10 19:09

tom


2 Answers

init() is called by the constructor.

init() isn't defined in the specification of PHP, it's only a method available with the Zend Framework to help initialize without having to rewrite the constructor yourself.


On the same topic :

  • Zend Framework: What are the differences between init() and preDispatch() functions in controller objects?
like image 181
Colin Hebert Avatar answered Oct 06 '22 00:10

Colin Hebert


__construct is a php magic method. It always exists and is called on object creation. init() is just a reguar method usually used in ZF..

like image 33
Sergey Eremin Avatar answered Oct 06 '22 01:10

Sergey Eremin