所以我正在研究学校项目的通知系统,目前我对此感到困惑。创建通知时,将使用四个属性创建Notification类的实例,其中一个属性是unix时间戳。然后,我将此对象传递给一个过程,该过程将四个属性插入到数据库表中。问题是出于某种奇怪的原因,四个属性中的三个都包含unix时间戳,包括unix属性,而第四个属性仍为空。在不同阶段回应属性表明问题是将通知对象传递给将其插入表中的过程。
创建通知类实例并将其传递给将其插入数据库的过程的过程。
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);
}
带有构造函数的通知对象
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;
}
}
最后,该过程将对象插入数据库
//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();
}
提前感谢任何可以帮助我的人!
答案 0 :(得分:3)
$ notification-> $ notificationUid应为$ notification-> notificationUid
在构造函数和addNotification函数中。
其他属性
相同