vendredi 6 septembre 2019

Nested shorthand if bug [duplicate]

This question already has an answer here:

I have this code below using nested shorthand if:

$foo = new stdClass;
$foo->type = 'regular';
$foo->group_one = 1;
$foo->group_two = 2;

$group_id = $foo->type == 'regular' ? $foo->group_one : $foo->type == 'agent' ? $foo->group_two : null;

var_dump($group_id);

I expected the value to be 1. Why the value of $group_id is 2?

Aucun commentaire:

Enregistrer un commentaire