samedi 2 mai 2020

Variables in if condition scope

There's not much about this argument on this community so I thought to drop this question.

I have this piece of code used for validating $params['full_name']:

$params = ["full_name"=>"John Doe"];
$full_name = $flag ? null : ( ( $tmp_name = trim(strip_tags((string)@$params['full_name']))
                            &&  (strlen($tmp_name) > 3 && strlen($tmp_name) < 30)
            ) ? $tmp_name : out('The full name must be 3-30 characters', 'Invalid full name'));

Despite of $params['full_name"] being populated correctly, I get a run-time error:

<b>Notice</b>: Undefined variable: tmp_name

Why is this happening? Am I just missing the theory of scoping inside if statements?

Aucun commentaire:

Enregistrer un commentaire