在构造函数和析构函数中读取会话变量的 I/O
我有一个页面在循环中被多次调用。我有一个版本,它在页面加载时从 MySQL 中提取数据,在页面再次重复该过程之前将修改后的数据推送回每次提交。其中一些数据仅对会话的运行很重要,在会话结束时转储
我正在考虑一个类的想法,该类从构造函数中的会话变量加载其变量,然后将最终值推回到析构函数中的相同会话变量。我有一些类似于以下内容的内容。变量在第一次调用构造函数时成功初始化,并由析构函数的第一个实例传递出去。但是,它们在第二次调用构造函数时无法加载。我错过了什么吗?
提前致谢
class counters
{
protected $qCounters;
function __construct()
{
$this->qCounters = $_SESSION['q']['counters'];
}
// process happen here to alter values
function __destruct()
{
$_SESSION['q']['counters'] = $this->qCounters;
}
}
I have a page that gets called many times in a loop. I have a version which is pulling data from MySQL on page load, pushing modified data back with each submission before the page repeats the process again. Some of this data is important only to the running of the session, being dumped at session end
I'm playing with the idea of a class which loads its variables, from session variables in the constructor, then pushes the final values back out to the same session variables in the destructor. I have something along the lines of the following. The variables are successfully initialised on first call to constructor, and passed out by first instance of destructor. However, they fail to be loaded on second call to constructor. Am I missing something?
thanks in advance
class counters
{
protected $qCounters;
function __construct()
{
$this->qCounters = $_SESSION['q']['counters'];
}
// process happen here to alter values
function __destruct()
{
$_SESSION['q']['counters'] = $this->qCounters;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
参考资料
References