So i'm working on a notification system for a school project and am currently baffled by a bug. When a notification is created an instance of a Notification class is created with four attributes, one of which is a unix timestamp. I then pass this object into a procedure which inserts the four attributes into a database table. The problem is for some bizarre reason three of four attributes all hold the unix timestamp including the unix attribute whilst the fourth remains empty. Echoing out the attributes at different stages showed that the problem is when the notification object is passed to the procedure which inserts it into the table.
The procedure which creates an instance of the notification class and passes it to the procedure which inserts it into the database.
require_once('notification.php');
require_once('database.php');
class NotificationStatic{
//Creates a new notification object and inserts it into the database
public static function CreateNotification($notificationType, $notificationUid, $notificationUidInvolved){
$notification = new Notification($notificationType, $notificationUid,
$notificationUidInvovled, time());
Database::AddNotification($notification);
}
The notification object with it's constructor
class Notification{
public $notificationType;
public $notificationUid;
public $notificationUidInvolved;
public $notificationUnix;
function __construct($_notificationType, $_notificationUid, $_notificationUidInvolved, $_notificationUnix){
$this->$notificationType = $_notificationType;
$this->$notificationUid = $_notificationUid;
$this->$notificationUidInvolved = $_notificationUidInvolved;
$this->$notificationUnix = $_notificationUnix;
}
}
And finally the procedure inserts the object into the database
//Inserts notification into the database
public static function AddNotification($notification){
self::Connect();
$notificationType = $notification->$notificationType;
$notificationUid = $notification->$notificationUid;
$notificationUidInvolved = $notification->$notificationUidInvolved;
$notificationUnix = $notification->$notificationUnix;
$sql = "INSERT INTO notifications(notification_id, notification_type
,notification_uid,
notification_uid_involved, notification_unix)
VALUES (DEFAULT, '$notificationType', '$notificationUid',
'$notificationUidInvovled', '$notificationUnix')";
self::$conn->query($sql);
self::$conn->close();
}
Thanks in advance to anyone who can help me out!