-1

This was working and then it stopped. That was in version 7.2.6 the latest.

if(!@include_once('config.php')) {
    echo 'failed';
}

So we've downgraded to 7.1.9 but it doesn't work there as well.

There is no error thrown, nothing. Just a blank screen. It's as if it's not even there...

If I echo something before that, it works. If I echo something after this, nothing happens.

Why is this happening?

Nikk
  • 7,384
  • 8
  • 44
  • 90

3 Answers3

0

Maybe you could try the advice around "example #4" on this page and see if that makes a difference? http://php.net/manual/en/function.include.php

E.g.

if ((@include_once 'config.php') === FALSE) { 
    echo "failed";
}

By the way: as other's have said, @ suppresses PHP warnings/errors for the line of code where it's applied.

My interpretation of your question is that you have used @ deliberately to suppress the engine's warning and echo your own message instead. If you removed the @ and the include failed, I'd expect to see the warning message output if errors are set to show, AND the word 'failed' should still be echoed afterwards.

Andrew Chart
  • 623
  • 6
  • 10
0

what, exactly, do you think @ does? it suppresses errors. so when you say There is no error thrown, nothing, this is totally expected, because if there is any errors, @ probably suppress them. remove the @, and if you can't trust your php.ini settings, do an ini_set call too, also set in some debug prints, eg

ini_set("error_reporting","-1");
echo "before include.";
if(!include_once('config.php')) {
    echo 'failed';
}
echo "after include";

then check your error logs after it executed.

hanshenrik
  • 19,904
  • 4
  • 43
  • 89
0

This is how I solved it.

if (!(@include 'config.php')) { die(json_encode(array('error'=>true))); }

I need the error to be suppressed because I wan't to handle the error without breaking my script—in a way that the other end know's it's an error and will inform the front-end user.

Nikk
  • 7,384
  • 8
  • 44
  • 90