I'm used to Perl, not to PHP, and I'm used to something like this:

open(FILE,">filename.txt") || die "$!";

where "$!" is the common variable for an error message.

How can I do this kind of thing in PHP?

Of course I can do

if( fopen(foo, bar) ){
  // something
} else {
  echo("there was an error");
}

but how do I figure out which error it was -- unsufficient permissions, file locked, file doesn't exist, etc?

My hosting provider has got their "display_errors" set to "Off" in the shared php.ini, and what I did was use this to turn errors back on:

  error_reporting ( 4096 );
  ini_set ( display_errors, 1 );

which seems to help, but when I try to print out to the browser any variable from $POST or $GET my script silently dies, even with the error setting above. I'm guessing this is a security measure? It's very confusing. How can I get around that?

    Try using error_reporting(E_ALL); (instead of 4096, which is only E_RECOVERABLE_ERROR type errors).

      See HERE for errors
      Here's more:
      value constant
      1 E_ERROR
      2 E_WARNING
      4 E_PARSE
      8 E_NOTICE
      16 E_CORE_ERROR
      32 E_CORE_WARNING
      64 E_COMPILE_ERROR
      128 E_COMPILE_WARNING
      256 E_USER_ERROR
      512 E_USER_WARNING
      1024 E_USER_NOTICE
      2047 E_ALL
      2048 E_STRICT
      4096 E_RECOVERABLE_ERROR

        It's best to use the pre-defined contants rather than the numeric values, both for code readability and in case the values change, as they have for E_ALL, which is 2047 up through v5.1, 6143 in v5.2, and 8191 in the latest versions.

        To make sure you see all potential messages, use:

        error_reporting(E_ALL | E_STRICT);
        

          Hah, you know what's funny? If you do that, it complains about E_STRICT not being quoted. Start as you mean to go on, I suppose...

            AmbroseChapel wrote:

            Hah, you know what's funny? If you do that, it complains about E_STRICT not being quoted. Start as you mean to go on, I suppose...

            That probably means you're using a PHP 4 or older, as E_STRICT was not introduced until PHP 5, in which case you can just use E_ALL by itself.

              Write a Reply...