mostafatalebi Posted November 26, 2012 Share Posted November 26, 2012 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 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. 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" Link to comment https://forums.phpfreaks.com/topic/271206-what-is-__constructor/#findComment-1395313 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.