By Borek-1 on
Following code generates user-visible warning:
$handle = @fopen($wp_config_file . '.inc', 'w');
PHP manual states that when I use @ sign, all errors and warnings should be suppressed. Do I misunderstand something or is it a Drupal bug?
Comments
Same Problem
I'm trying to use the PayPal services package, which contains a bunch of file includes that use the @ syntax. Yet, the unfound files show up as user-visibile warnings. I shouldn't have to be hacking the package, since it works fine in non-Drupal pages, so what gives?
Can't Wait for an Answer, Here's a Workaround for Those Who Need
How to get around problems inherent in both PHP and Drupal when using @ before your include() statement...
Now, you might think the following simple if would do the trick:
But you can see in the comments on this page [http://php.net/manual/en/function.error-reporting.php] why that won't work. is_file() doesn't take into account the PHP include_path configuration option, so it doesn't look for the file in all the places that include() does.
The following method takes the include_path into account, and as an added bonus, does not suppress errors in the included files if found (which @ will do, even though it shouldn't).
If you want to use require() instead of include(), set the $require argument to 1 when you call include_safe(). If you want to include_once() or require_once(), set the $once argument to 1.
To insure that the variables in your included file exist in the same scope as the page doing the including, the function is set up to return a line of code that you must then evaluate outside the function.