Logical error in ternary operator
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 ?
$user->data['user_id'] = 36412
is not equal to
ANONYMOUS = 1
(36412 != 1) So the first "AND"-Condition failes and your else-"Block" will be evaluated.
精彩评论