I want to create a static class in PHP and have it behave like it does in C#, so
- Constructor is automatically called on the first call to the class
- No instantiation required
Something of this sort...
static class Hello {
private static $greeting = 'Hello';
private __construct() {
$greeting .= ' There!';
}
public static greet(){
echo $greeting;
}
}
Hello::greet(); // Hello There!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…