Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign changed variable to the same variable is safe?

Is this good practice and is there any chance of fubar if i assign slightly changed value of variable to itself?

e.g.

$myVar = 1;
$myVar = $myVar + 33959902;
$myVar = rtrim($myVar,2);
$myVar  = explode(",",$myVar);

i know this will work but is this safe to do so in PHP?

like image 963
JohneXXKSS Avatar asked Jan 22 '26 18:01

JohneXXKSS


1 Answers

This violates the practice of using good variable names -- if the variable truly represents the same thing then I would consider re-assigning to it. As it does not represent the same thing in this case, I consider it "bad" or "code smell".

(It will, however, "work safely" otherwise.)

Happy coding.