Jump to content

Question about the way some objects work in PHP


criostage

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.