我已将PHP对象(类login
)保存到会话变量$_SESSION["login"]
中。课程login
包含__sleep()
和__wakeup()
方法。
在将对象保存到会话之前,我在其上应用了serialize方法。
在另一个页面上,我使用此会话变量。如果我第一次执行unserialize($_SESSION["login"])
我没有问题。但是如果我第二次使用相同的命令,结果会改变。
var_dump($_SESSION["login"]); // everything is how expected and how I saved it
$temp = $_SESSION["login"]; // here I try to copy the content of the session variable
$un_ser = unserialize($temp); // I use unserialize to get the original object
var_dump($_SESSION["login"]); // Problem: not the same as before! Why has it changed?
问题是我想用login
读取unserialize($_SESSION["login"])
- 对象超过一次,但目前在我看来这是不可能的,因为会话变量在{{{{}}之后发生变化1}}。
具体来说,我保存到会话中的字符串最初是:
unserialize(...)
但在O:24:"BSHelper\login":2:{s:12:"*logged_in";b:1;s:9:"*lehrer";O:22:"BSCore\lehrer":7:{s:12:"*id_lehrer";s:1:"1";s:13:"*geschlecht";s:4:"Herr";s:11:"*nachname";s:10:"testsurname";s:17:"*unterrichtsart";s:6:"Praxis";s:21:"*unterrichtsartKurz";s:1:"P";s:11:"*farbcode";s:7:"#F0BB86";s:8:"*email";s:26:"test@mail.com";}}
会话变量更改为此
unserialize(...)
我认为能够从会话变量中访问整个对象真的很有意义,因为这样可以访问值,特别是对象的方法。