What are the reasons to implement the init() method when there is the constructor method in PHP?
-
I've seen many libraries that require to call the init() method before performing the functionality they provide. And often no parameter is passed to the method. I'm wondering why they design like so when it's possible to set up necessary property values in the constructor. If the user wants to reset the settings, what's wrong with re-instantiating the object?
-
Answer:
I can't say for PHP.. However in java frameworks like Spring and EJB, There is a difference between the time an object being created, and the time it can start using a framework. When the framework loads, it starts creating all the objects that it needs. However, while it's creating objects, the framework is not completely ready yet, because it's not done loading everything that it needs to. There can be cases where the object needs to use the framework to initialize itself. It can't so it in the constructor because the framework is not ready. So, you add an init method that is called by the framework after the framework is ready
Jayesh Lalwani at Quora Visit the source
Related Q & A:
- Why do agencies lose clients, what are the reasons?Best solution by Yahoo! Answers
- What could be reasons I am not losing weight?Best solution by Yahoo! Answers
- What are medical reasons to get a nose job?Best solution by ChaCha
- What are the reasons behind?Best solution by wiki.answers.com
- What are main reasons to attend a college?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.