-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?

10
  • So what does your http servers error log file reveal what is happening? Commented Jun 23, 2018 at 10:46
  • @arkascha Nothing in the PHP log file /var/log/php_errors.log. HTTP returns 200. Unbelievable. Not seen anything like this before with PHP. Commented Jun 23, 2018 at 10:48
  • 1
    try with removing @ Commented Jun 23, 2018 at 10:48
  • 3
    Of course there's no error thrown! You suppressed it with @ Commented Jun 23, 2018 at 10:50
  • 1
    Also, if you want to thrown an error if a file cannot be included, you can use require or require_once. Commented Jun 23, 2018 at 10:53

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.