开发者

Logical error in ternary operator

开发者 https://www.devze.com 2023-04-10 20:17 出处:网络
Can somebody explain me why that ternary operetor return the second option instead of the first ? This is the code :

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号