I just transferred a PHP website from a Linux server to Windows. Everything seems to function the same except one huge difference:
On the Linux server, the following piece of code is ignored when $_GET['action'] is not set:
$action = $_GET['action'];
if($action=='add'){
echo 'good';
}
However, this prevents the page from loading on the Windows server.
What does work is:
if(isset($_GET['action'])){
$action = $_GET['action'];
}else{
$action='';
}
if($action=='add'){
echo 'good';
}
2 questions:
-
Is there a way to configure the server to be more forgiving of variables that don’t have a value?
-
Is the second code example better practice?
putting an
@symbol infront of the variable will tell php to ignore the error. but i consider this as bad practice.i do consider it as a good practice, it is always good to check.
IMO you should go for second, you can always use a ternary operator. so instead of
you can write
both does the same thing.