PHP error when host changes

Asked

Viewed 53 times

0

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

if(!saber_se_não_existe) {}

It always worked as well as this

if(saber_se_existe) {}

So much so that I rediscovered my entire code replacing EMPTY and ISSET with this one that got show but today I went to run in PHP localhost and this does not work, I had to change everything to ! Empty or Empty and PHP is also 7, what allows this is some extension? if yes, can you tell me which one? i on localhost used PHPDESKTOP both 47 and 53 give the same error but online no.

Edit

I have an IF condition that checks if a variable was set that in this case is used isset and to know if Empty is empty, ie

$existe = true;
$nao_existe = false;

Soon

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

and

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

as well as I can use the

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 from above, that it is enough to do

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

and

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

only this, however, my online server, both in an android emuloader and an internernet Shared, work the latter, but on my localhost with PHPDESKTOP of

Undefined index

  • 1

    i found your example incomplete. saber_se_existe is a count? can’t really understand what you want

  • I could explain your example better?

  • @Kayobruno is not a constant, in fact it is only knowing if there is the variable or not, the yes, of course, I will reformulate

  • @Karlzillner I will redo and put something better

1 answer

0


Your environments are with different configurations of error reporting.

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

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

The combination of possible values in these two settings causes some servers to complain about more aspects of their 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 variables tested was not previously declared (undefined index, índice não declarado), which is a good practice but is not mandatory. This is not a defect (hence the level NOTICE, nay WARNING or ERROR).

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

Production servers has display_errors = false for whom even if an error happens this does not necessarily appear to your visitors (but stay registered in the visible log for developers).

error_reporting

display_errors

  • in case only need to change the error Reporting, however one thing you mentioned is that it does not prevent the operation of the application, in this case these errors prevent the functioning, are sensitive parts that make know if the user is logged in or not and these errors prevent the application from performing the checks, for example. but I will set up here and return now

  • everything I try to change like for example to Off or False or even error_reporting(0); make the program lock completely

  • @flourigh these settings don’t have the power to lock your program unless the syntax is wrong. Something else is causing this. Try placing error_reporting = E_ALL and display_errors = true and restart apache/Nginx before testing. Then go fixing all the errors that appear, one by one.

  • I’m beginning to think that PHPDESKTOP’s error is some kind of BUG because all the options I put in php.ini make the program crash

  • I’m using PHPDESKTOP so it might be a BUG but on their github wiki I found nothing

  • yeah, I really think it’s a defect in PHPDESKTOP because in USBWEBSERVER I turned off display_errors and it worked normally with it already connected from the same error of PHPDESKTOP but in USBWEBSERVER when it turns off works normal, already in PHPDESKTOP when it turns off the entire program hangs

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.