criostage Posted October 12, 2011 Share Posted October 12, 2011 Hello, i been making a site to learn some PHP. I been always searching about what's the best way of using the PHP functions, classes and objects but i have a small question that i couldnt found the awnser by my self. so far i m inicializing an PHP class like this: 1st case $themeobj = new theme(); Today i found an tuturial that used an other way of calling an function inside the class: 2nd case theme::loadTheme; I understand that the way i m doing, your iniciating the variable $themeobj as an object of the class theme and that the theme:loadTheme just calls the function loadTheme inside the theme class (please correct me if i m wrong), but here's where is where i need abit of enlightment. Using the 2nd case will "skip" the loading of the __construct function? when should you use the 1st case or the 2nd case? Every time i needed an function from theme i would use $themeobj->loadTheme($param) its safe to use theme::loadTheme($param)? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/248962-question-about-the-way-some-objects-work-in-php/ Share on other sites More sharing options...
titan21 Posted October 12, 2011 Share Posted October 12, 2011 The format class::function() is a static function wich means that you don't need an instance of the class inorder to execute it. $obj - new Object() instantiates a new instance of the class. By default, this always calls the magic method __construct(). Quote Link to comment https://forums.phpfreaks.com/topic/248962-question-about-the-way-some-objects-work-in-php/#findComment-1278618 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.