Hello,

I'd like how to suppress warnings so they won't show up on pages or logs.
I'm creating my own module, and in a part of the code, I have to use exif_imagetype() to check whether an image file exists or not.

The problem is, drupal outputs the warnings if the file doesn't exist, while I contend a FALSE return value would suffice.

@ doesn't work in my case, and I don't have the access to modify php.ini if you ask me.
I tried to do the same thing in a file on the same server where the drupal site is installed, and it didn't output any warning.

Thank you for your attention.

Comments

styro’s picture

You can prevent warnings and errors showing on the screen at /admin/settings in the error handling section.

As for the exif_imagetype() warning, shouldn't you check whether or not the file exists first before checking its type? That way the FALSE warning from the function is still meaningful - it would alert you to possibly corrupt or invalid image files etc.

--
Anton
New to Drupal? | Forum posting tips | Troubleshooting FAQ

Arto’s picture

I have to agree with thekid that the current behavior of Drupal's error handler with regards to @-suppressed warnings is somewhat unfortunate.

I'm in the same boat with a module I'm developing: the FALSE return value from @rmdir() is the desired useful behavior in this case, but due to the warning getting written to the watchdog log despite the @ sign, I'm going to need to add an unnecessary extra check to prevent the spurious message. C'est la vie.

--
Arto Bendiken -- currently working on static page caching for Drupal 4.7.

plumbley’s picture

In your module, use is_file() to check if the file exists first (see e.g. theme_image() in theme.inc). Then you won't do anything that makes any warnings :-)

Use warnings and notices to help you! Drupal core is even being weaned off of Notices (see http://drupal.org/node/34341). Once you get rid of all the Notices about unset variables, there are can sometimes be a few sneaky bug-ettes that it would be hard to spot otherwise (e.g. misspelled defined constants).

(Of course, you don't want anything nasty to show up on pages your users see. Setting "Error reporting" in ?q=admin/settings to be "Write errors to the log" should suppress the error display on a production site. On a non-Drupal site, using ini_set() to set display_errors to 0 would have a similar effect.)

Best wishes,

Mark.

www.PostgraduateStudentships.co.uk - where ideas and funding meet

thekid’s picture

Thank you so much for the inputs and comments.

is_file() does indeed work.
If I recall correctly, I used that function in my other PHP file (long before I knew Drupal), and I encountered a problem.
A friend of mine suggested getimagesize(), and it worked for my case.
Later, I found out exif_imagetype() would do the better job than getimagesize(),
so then I changed the bit of code. Both work fine outside Drupal module until this day, but not for Drupal.
When I used that chunk of code to a module, I had that warnings. But it's fixed now :D

You all make a good point about warnings.

Thanks a bunch for your help.
Have a nice day :)