Posted by darius on 04/04/07 17:33
Hi
I started out writing a class wrapper for 3DES encryption called TDES.
It seemed logical to declare encrypt() and decrypt() methods as static,
so I can just call, e.g., TDES::encrypt("plaintext") without creating an
object. Then I wrote a class for outputting html (htmlhead() htmlfoot()
htmlform() etc.) and once again I find myself just using static functions
b/c they made sense there too. Now I'm writing a wrapper for SoapClient
and again I'm making call() and setCookie() and variousotherthings()
methods static. Is this idiotic? Do I need help? When is it proper to
use static?
Related questions:
1) If I have a static variable, the scope is only for that http request,
correct? Other invocations of the script will have a different copy of
the variable? (I'm not creating several objects of the same class in my
app.)
2) how do I initialize a static variable when I need to do more than just
set it to some constant expression. Right now I do this
class myclass {
private static myvar;
public static init() {
myclass::myvar = // whatever
}
}
myclass::init();
Slightly inelegant.
[Back to original message]
|