I'm studying a condition and I don't understand because one of the conditionals is set to true by default, without setting a variable before, does anyone tell me what this means?
$pagina= Pagina::findOrFail($datos->idpagina);
switch ($datos->tipodato)
{
case 'logo':
if(true) //??
{
$datos->logo = urldecode($datos->logo);
$datos->logo = str_replace(' ', '+', $datos->logo);
$datos->logo = str_replace("data:image/png;base64,","",$datos->logo);
$datos->logo = str_replace("data:image/jpg;base64,","",$datos->logo);
$datos->logo = str_replace("data:image/jpeg;base64,","",$datos->logo);
$pagina->logo =$datos->logo;
}
else
{
$pagina->logo =$datos->logo;
}
$nombreimagen="img".$datos->idpagina.".png";
file_put_contents(public_path()."/imagenes/{$nombreimagen}",
base64_decode($datos->logo));
$pagina->archivologo=$nombreimagen;
break;
It means that the code inside the if-statement always be executed and the code inside the else-block will never be.
A common reason is that it once was a condition based on a variable, but a programmer has inactivated it, but kept the else statement to make it easier to restore.
if (true)
means, that the then case is always executed and you could savely remove the else
case (and also the condition itself). Mostly this is inserted for debug cases or refactorings and somebody forgot the remove the redundant if condition.