| 1 | <?php |
||
| 7 | trait SingletonTrait |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Instance of itselfs |
||
| 11 | * @var self |
||
| 12 | */ |
||
| 13 | private static $instance = null; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Return the instance of the used class |
||
| 17 | * @return self |
||
| 18 | */ |
||
| 19 | public static function getInstance() |
||
| 26 | |||
| 27 | /** |
||
| 28 | * private constructor for calling an optional init-Method |
||
| 29 | */ |
||
| 30 | final private function __construct() |
||
| 34 | |||
| 35 | private function init() |
||
| 44 | } |
||
| 45 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: