三元运算符的逻辑错误
有人能解释一下为什么三元运算符返回第二个选项而不是第一个吗?
这是代码:
$token_sid =
($user->data['user_id'] == ANONYMOUS &&
!empty($config['form_token_sid_guests'])) ? $user->session_id : '';
这是我实际测试的值
$user->data['user_id'] = 36412
ANONYMOUS = 1
$config['form_token_sid_guests'] = 0
$user->session_id = 4c148b664b7284ecb776c0a932ddf008
$token_sid = ''
知道为什么返回空值而不是用户会话 ID 吗?
Can somebody explain me why that ternary operetor return the second option instead of the first ?
This is the code :
$token_sid =
($user->data['user_id'] == ANONYMOUS &&
!empty($config['form_token_sid_guests'])) ? $user->session_id : '';
And here are the values for my actual testing
$user->data['user_id'] = 36412
ANONYMOUS = 1
$config['form_token_sid_guests'] = 0
$user->session_id = 4c148b664b7284ecb776c0a932ddf008
$token_sid = ''
Any idea why that return the empty value instead of the user session id ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不等于
(36412 != 1)
因此,第一个“AND”条件失败,并且将评估您的 else“块”。
is not equal to
(36412 != 1)
So the first "AND"-Condition failes and your else-"Block" will be evaluated.