Use static class here?
Posted: Fri Feb 08, 2013 8:16 pm
I'm writing a class that allows me to send an email randomly throughout my app. basically administrator notifications to myself. I don't want to have to instantiate the class every time I want to do this so i'm using a static class.
Question 1) Is this a good use of a static class?
Question 2) Thoughts on my class?
Question 3) Any thoughts on why i run this code i get the error " classes that i write Fatal error: Call to undefined method Notify::sendNotification() in classes/testclass.php on line 5"
testclass.php
Question 1) Is this a good use of a static class?
Question 2) Thoughts on my class?
Question 3) Any thoughts on why i run this code i get the error " classes that i write Fatal error: Call to undefined method Notify::sendNotification() in classes/testclass.php on line 5"
Code: Select all
class Notify {
private $email = "email@awesomesauce.com";
private $phone = "";
private $sms;
private $subject;
private $message;
public static function sendNotifiction($subject, $message, $sms) {
self::$subject = $subject;
self::$message = $message;
self::$sms = $sms;
}
private function sendEmail() {
mail(self::$email, self::$subject, self::$message);
if (self::$sms) {
mail(self::$phone, self::$subject, self::$message);
}
}
}Code: Select all
Notify::sendNotification("testing subject","testing message", true);