Yeah, there's two things you can do to get rid of this warning. What you said:
$smith = "";
if($submit == "button_a") {
$smith = "button_a";
}
elseif($submit == "button_b"){
$smith = "button_b";
}
Or check if it's set when you print it:
<?php
if( isset( $smith)) {
echo($smith);
}
?>
However, this is just a warning, and it is letting you know that there is a condition that $smith
won't be defined (when $submit
isn't "button_a"
and isn't "button_b"
). If that condition were to occur, you would be printing $smith
when it wasn't set, which could be a bug in your script.
You can tell PHPStorm to ignore undefined variables reports if require on include statement are located in the same execution flow before the variable access. You'll find it in 'Undefined variable' - Ignore 'include' and 'require' statements. It is enabled by default, so you should disable it.
Note: The setting is in File > Settings (Ctrl+Alt+S) > Project Settings > Inspections > PHP > Undefined > Undefined variable