I am confused whether to use static method or just simple method.
Lets me give an example, I am using Zend framework 1 project.
I have class like
class Example1
{
public static function getVariable() {
return is_numeric(Zend_Registry::get('config')->Variable) ? Zend_Registry::get('config')->Variable : 0;
}
public function calculateSome($param1, $param2) {
$response = array();
if($param2 == 0) {
$response = number_format(($param1 * self::getvariable()) /100);
} else {
$response = $param1;
}
return $response;
}
}
Usage :
- Currently i'm getting variable value like
Example1::getVariable()
in whole project. - And Calculating like first instantiating a class
$class1 = new Example1();
and then calling the function like$class1->calculateSome(1, 0);
I am confused whether it is good to change calculateSome()
to public static
and call like this Example1::calculateSome(1, 0)
or left as it is.
I Have found link when to use static => When to use static vs instantiated classes
But I can't understand what it says.