Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Namespaces vs Classes with static functions

Tags:

php

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.

like image 740
JackMahoney Avatar asked Sep 05 '25 20:09

JackMahoney


1 Answers

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

like image 84
topdown Avatar answered Sep 10 '25 11:09

topdown