I want to gauge people's opinions about using static classes instead of namespaces. I come from the C ++ background and really love its syntax and how it allows you to structure the code. I recently decided that I need to group code into logical units, not just files. For example, I prefer calls like User :: login to user_login. So, I did a bit of search engine work and was relieved to find that PHP has namespaces. My relief did not last long; I really dislike the syntax; this adds more clutter to my function calls. So, for now, I'm using static classes to simulate namespaces. Are there any flaws in this?
I found a similar question in PHP Namespaces vs Classes with static functions , but discussions were not discussed.
In addition, is there a way to avoid the following situation:
class Test {
public static void myFunc() {
Test::myOtherFunc();
}
public static void myOtherFunc() {
}
}
I suggested that it would be normal to call functions in the same class without specifying a name, but apparently not. Are there any workarounds for this (for example, in C ++ there is a using keyword).
source
share