完整示例: A)預計會發生什麼。 預計將數據保存在$_SESSION["user_data"]
變量中。這意味着如果我做print $_SESSION["user_data"]->getUUID();
它必須打印用戶UUID,因爲它定義在這裏:$_SESSION["user_data"] = UserRep::selectUser(Conn::getConnection(), $token);
PHP - 會話無法存儲類?
B)究竟發生了什麼。 它實際上返回一個錯誤:
Fatal error: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "UserMan" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in C:\xampp\htdocs\esotic1jdv\index.php on line 67
注:該生產線67 <?php echo $_SESSION["user_data"]->getUUID(); ?>
但下面的代碼做的工作: $data = UserRep::selectUser(Conn::getConnection(), $token);
然後 print $data->getUUID();
C)的例子我想要發生的事情。
<?php
print $_SESSION["user_data"]->getUUID();
必須奉獻的結果:
569047265eca48a8aa34847a3a059a7ea8170dc3
d)實際上會發生什麼。 getUUID(); 給的結果是:
Fatal error: main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "UserMan" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in C:\xampp\htdocs\esotic1jdv\index.php on line 67
請停止向會話添加對象。這充其量只是一個維護/調試噩夢,還有一個安全漏洞等待最壞的時候發生。 – PeeHaa
我可以做些什麼@PeeHaa?只保存UUID,然後通過它獲取數據? –
我第二次PeeHaa的評論:在會議中越少越好。是的,存儲UUID然後從數據庫獲取用戶更好。如果你擔心速度問題,那麼很多數據庫都有緩存,或者(我的首選)是自我序列化對象的關鍵部分,以便重新創建它並從緩存(如果可用)重新創建,並回退到DB(如果在緩存中不可用)。 – Robbie