0

I expect the output of "inside test finish" when loaded the index.php file instead I got nothing.

index.php:

<?php
@include_once('functions.php');
test();
echo "finish";
?>

inside the functions.php there's a

<?php
function test()
{
  echo "inside test";
}
Jacob
  • 77,566
  • 24
  • 149
  • 228
lilzz
  • 5,243
  • 14
  • 59
  • 87
  • How are you viewing the file? Do you have a server setup? Have you been able to get any basic PHP code to work? – Percy Aug 13 '11 at 04:28
  • 1
    Forget the separate function file for a minute. Does `` in index.php work? – User Aug 13 '11 at 04:30
  • yes, apache is up and running and able to echo "inside index.php" out to the browser. – lilzz Aug 13 '11 at 04:31
  • Is functions.php found? Try setting display_errors on in php.ini, and set error_reporting to E_ALL, as well as removing the @ before your include – JRL Aug 13 '11 at 04:33
  • Another thing is I commented out the test(); the "finish" won't show up when the include_once is there. When include_once gone, "finish" shows up on browser. – lilzz Aug 13 '11 at 04:34
  • if (!@include_once('functions.php')) die("Missing Functions"); to be exact. It didn't say Missing functions so it's OK. – lilzz Aug 13 '11 at 04:35

4 Answers4

3

You are suppressing errors by prefixing the include_once statement with @. Try removing it so you can see any possible errors that PHP is emitting.

Delan Azabani
  • 79,602
  • 28
  • 170
  • 210
0

@ suppresses errors. Was there a path or syntax problem? You wouldn't know because you're not getting an error output. Your code is fine.

Josh
  • 12,602
  • 2
  • 41
  • 47
0

Hehe, is it just me or just an copy/paste issue but aren't you missing the ?> at the end of functions.php:

<?php
function test()
{
  echo "inside test";
}

and since @ is on and is suppressing errors as everyone else has mentioned, it may be the reason why there is no output.

Jasoneer
  • 2,078
  • 2
  • 15
  • 20
  • You don't need the `?>` at the end. See this [SO question](http://stackoverflow.com/questions/3219383/why-do-some-scripts-omit-the-closing-php-tag#3219401). – Shoan Aug 13 '11 at 04:42
  • That's very interesting and good to know. I never paid too much attention to trailing whitespace after the closing tag because I always remove any trailing whitespace anyways. – Jasoneer Aug 13 '11 at 19:05
-1

The @ does not only suppress errors, but, in fact, suppresses all output from that file/function/whatever. Even if there were no syntax errors in your functions.php file, it would have not output anything anyway. It is generally bad practice to use the @ operator for anything, rather just write good code!

paulscott56
  • 496
  • 4
  • 7