Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
class validate(){
function is_number($num){
return is_numeric($num);
}
}
//used like this
validate::is_number($num);
The study guide says that the advantage of avoiding naming conflicts in a library isn't enough to justify the overhead assoicated with using a class this way. So my question is what is the overhead? Do you agree or disagree? What do you think is a justifiable use for making a class like this?
if there's any remote possibility that the function you are creating may already exist in the user's code (a given with a lot of code), a namespace helps a lot. I use namespaces in C a lot, but haven't used them too often in PHP. Although soon I will as projects I'm working on will be used by many others (as you may know.) Anyways, the performance hit is that it is a class, since PHP isn't natively an OOP system, there are tiny performance hits each time a class is interacted with, although fairly minimal, they do add up.
neophyte wrote:According to the Zend cert study guide a namespace is a class with methods that are used statically.
A "class with methods" is not a namespace in the true sense of the word. The class constuct can be used to create a namespace. However, there is really no namespacing difference between:
PHP seems to do 2 hash lookups every time class function is invoked. Honestly, sometimes I get the feeling that writing my own include function and using tokenizer to optimize stuff would be a good idea.
On what version of PHP was that benchmark run? Was that the average of many runs? Did you time it with the order of the tests reversed? Those numbers look a lot closer than I remember. I seems like unless you are writing a "loop a million times an call a function each iteration" program, the difference trivial.