I am a new in terms of PHP OOP programming, i don’t understand when and how the following class names are and when shall i use them :
$a = new Classname();
$a = new Classname;
$a = ClassName::function();
$a = ClassName::getInstance();
Many thanks and sorry for silly question:
These are identical.
You can use them interchangeably when the class constructor does not take, or does not require other parameters.
Example:
In this case you can use
$a = new Classname;and$varwill take the default value, or$a = new Classname('hello')and$varwill be equal to the value passed.These are both static method calls.
One calls a method called “function” (which cannot exist – it is a reserved word), the other calls a method named “getInstance”. When you use them really depends on what the methods do.
Static methods can be called without creating an object instance.
I.e.
versus