Page 1 of 1
Using Static Class Functions
Posted: Sun Apr 03, 2005 7:48 pm
by harrisonad
I am aware of the common (ei. standard) use of static class functions using the operator "::". What is the reason for using this technique? I mean, why not use a function in ordinary way, such as "HTML::CreateForm();" to just "CreateForm();" function call?
Thanks in advance for your reply...
Posted: Sun Apr 03, 2005 8:37 pm
by feyd
some are for organizational things. I use them a lot because of potential function name conflicts, or when I don't want people to instance the class they are housed in. This is similar to the concept of namespaces in C.
The SHA256 class I wrote for instance, isn't meant to be instantiated. Partly because of the generic interface it uses, and partly because getting a new hash would require creating a new instance of the class, pretty much.
Unless you name your functions VERY unique names, I'd expect them to collide with some other library at some point, especially if they are quite generic names, such as CreateForm()
RE
Posted: Sun Apr 03, 2005 9:17 pm
by harrisonad
Thanks pal,Now I know...
Yet, as a follow-up question, Which executes faster: a regular function class or that of a class?
Posted: Sun Apr 03, 2005 9:23 pm
by feyd
do you mean a "standard" function versus a class method?
I haven't done any tests on the subject, but I'd guess the class would be very very very slightly slower.. but that depends on how PHP's core handles those kinds of things. In C, there's rarely much of a difference.. but that depends on what you are doing in it, and how you are doing it.
RE
Posted: Sun Apr 03, 2005 10:17 pm
by harrisonad
What i mean is:
Which executes faster;
echo Tag('TR');
or...
echo HTML::Tag('TR');
Posted: Sun Apr 03, 2005 10:19 pm
by feyd
why not test it for yourself?
