Jump to content

Question about the way some objects work in PHP


Recommended Posts

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



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

Link to comment
Share on other sites

The format




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().

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.