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...
Using Static Class Functions
Moderator: General Moderators
- harrisonad
- Forum Contributor
- Posts: 288
- Joined: Fri Oct 15, 2004 4:58 am
- Location: Philippines
- Contact:
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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()
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()
- harrisonad
- Forum Contributor
- Posts: 288
- Joined: Fri Oct 15, 2004 4:58 am
- Location: Philippines
- Contact:
RE
Thanks pal,Now I know...
Yet, as a follow-up question, Which executes faster: a regular function class or that of a class?
Yet, as a follow-up question, Which executes faster: a regular function class or that of a class?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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.
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.
- harrisonad
- Forum Contributor
- Posts: 288
- Joined: Fri Oct 15, 2004 4:58 am
- Location: Philippines
- Contact:
RE
What i mean is:
Which executes faster;
echo Tag('TR');
or...
echo HTML::Tag('TR');
Which executes faster;
echo Tag('TR');
or...
echo HTML::Tag('TR');
Last edited by harrisonad on Sun Apr 03, 2005 10:19 pm, edited 1 time in total.