mostafatalebi Posted November 26, 2012 Share Posted November 26, 2012 (edited) Hello everybody What is the purpose of using __constructor? I know it has something to do with initialization, but I have not swallowed it as I should. I need a very clear literal description. Thanks Edited November 26, 2012 by mostafatalebi Quote Link to comment https://forums.phpfreaks.com/topic/271206-what-is-__constructor/ Share on other sites More sharing options...
Christian F. Posted November 26, 2012 Share Posted November 26, 2012 It is the function that's run every time a new object is created. Which means that every time you write new YourClass ($Param) the contents of $Param gets send to the class' __constructor (). You can find more information about this in the PHP manual, when reading about the OOP syntax. PS: Do take note of the fact that you cannot return anything from the constructor, as the new operator returns an object of the class instead. Quote Link to comment https://forums.phpfreaks.com/topic/271206-what-is-__constructor/#findComment-1395281 Share on other sites More sharing options...
requinix Posted November 26, 2012 Share Posted November 26, 2012 PPS: it's "__construct" Quote Link to comment https://forums.phpfreaks.com/topic/271206-what-is-__constructor/#findComment-1395313 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.