未设置会话变量会停止执行
我对这段代码非常着迷,并将其范围缩小到 unset 函数。当我对会话变量调用 unset 时,PHP 不会执行超出该点的任何操作。有人可以帮忙吗?
public static function print_session_notification() {
if( isset( $_SESSION['notification'] )) {
$session_notification = $_SESSION['notification'];
$output = '<div class="error">';
$output .= $_SESSION['notification'];
$output .= '</div>';
unset( $_SESSION['notification'] );
return $output;
}
}
我调用 print notification::print_session_notification();来自标头包含。标头包含由函数调用。 $notification 对象在调用头文件的函数中是全局的。
I have been going crazy over this piece of code and narrowed it down to the unset function. When I call unset on the session variable, PHP doesn't execute anything beyond that point. Can someone please help?
public static function print_session_notification() {
if( isset( $_SESSION['notification'] )) {
$session_notification = $_SESSION['notification'];
$output = '<div class="error">';
$output .= $_SESSION['notification'];
$output .= '</div>';
unset( $_SESSION['notification'] );
return $output;
}
}
I call print notification::print_session_notification(); from a header include. The header include is called by a function. The $notification object is global in the function that calls the header file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过向构造添加一个方法并将会话值分配给公共属性来解决该问题。谢谢你们的帮助!
I fixed the issue by adding a method to the construct and assigning the session values to public properties. Thanks for your help guys!!!
请确保在标头上设置了 session_start() 函数,并将 register_globals 设置为“ON”。
有关更多信息,请阅读 http://www.php.net/manual/en/function.unset.php
Please make sure that you set session_start() function on you header and set register_globals to "ON"
For more information read the comments on http://www.php.net/manual/en/function.unset.php