Reputation: 3433
Should I use classes with static functions or namespaces to better organise a PHP project growing in size?
I come from a Java background and like having static variables/functions available.
Upvotes: 4
Views: 3234
Reputation: 1106
Yep you can set the variable as static.. or you can look at class const as well.. this way you are avoiding global variables, can determine from which class you are accessing, and won't need to instantiate the class to get the value..
Upvotes: 0
Reputation: 456
The 2 features are completely different from each other.
The static keyword is to make a property or method available without an actual class instance. http://php.net/manual/en/language.oop5.static.php
On the other hand Namespaces are for organization and avoiding naming collisions. http://www.php.net/manual/en/language.namespaces.rationale.php
Upvotes: 3