PHP error when changing host

0

Good afternoon, I used an online host with php 7 and I had the following syntax

if(!saber_se_não_existe) {}

It has always worked as well as well

if(saber_se_existe) {}

So, I have refactored my entire code by replacing EMPTY and ISSET with this show, but today I was running PHP on localhost and this does not work, I needed to change everything to! empty or empty and PHP is also 7. does this allow any extension? If so, can you tell me which one? I in localhost I used PHPDESKTOP both 47 and 53 give the same error but not online.

edit

I have an IF condition that checks if a variable has been set that in case the isset is used and to know if the empty is empty, that is

$existe = true;
$nao_existe = false;

Logo

if(empty($existe)) {
// não mostra pois existe
}

and

if(isset($nao_existe)) {
// mostra pois existe, mesmo estando vazia
}

Just as I can use

unset(variavel_com_ou_sem_valor);
$varialvel_com_ou_sem_valor ? false : true;

There are many ways to do it, so much so that I discovered the example above, that just do

if($variavel_com_ou_sem_valor) {
// se tem mostra
}

and

if(!$variavel_com_ou_sem_valor) {
// se não tem mostra
}

But this, however, my online server, both in an android emulator and an internernet shared, work the latter, but in my localhost with PHPDESKTOP da

  

undefined index

    
asked by anonymous 02.06.2017 / 18:59

1 answer

0

Your environments are with settings other than error reporting .

If you look at php.ini or phpinfo() of each, you will see two settings:

error_reporting = E_ALL # ou outro valor
display_errors = true # ou false

Combining the possible values in these two settings causes some servers to complain about more aspects of your code than others. If you change the values to be the same, you will see the same errors in both environments (as long as it is the same version of PHP).

In your specific case one of the environments is reporting that one (or more) of the tested variables was not previously declared ( undefined index, índice não declarado ), which is good practice but not required. This is not a defect (so the level NOTICE , not WARNING or ERROR ).

In general, development servers have display_errors = true and set the error_reporting level to the desired level.

Production servers have display_errors = false for whoever an error happens this does not necessarily appear to your visitors (but be registered in the log visible to developers).

error_reporting

display_errors

    
03.06.2017 / 12:11