I am trying to work out whether the private static method in the example below should be non-static. It is only concerned with the static properties of the class which leads me to believe it is okay as a static method. However, it is only invoked from a non-static method, which suggests it should be a non-static method too.
I understand when a public method should be static, but not when a private method should be static.
Thanks in advance for your advice!
<?php
class MyClass
{
private static $initialized = false;
private static $staticProperty1;
private static $staticProperty2;
private $normalProperty1;
public function __construct($normalProperty)
{
$this->normalProperty1 = $normalProperty;
}
public function doSomething()
{
self::initialize();
// Now do some other stuff
}
private static function initialize()
{
if (!self::$initialized) {
self::$staticProperty1 = 'Hello';
self::$staticProperty2 = 'World';
self::$initialized = true;
}
}
}