I've seemingly tried about every different suggestion provided through a couple hours of Google and stackoverflow searching to no avail, and I cannot seem to suppress a large sum of "Deprecated: Assigning the return value of new by reference is deprecated in " errors presented at the top of my application, as well as Many "Warning: the magic method __get() (and __set()) must have public visibility and cannot be static in . Thus far, I have added the following line and many different variations of it to my php.ini file:
error_reporting = E_ALL & ~E_DEPRECATED
error_reporting = E_ALL ^ E_DEPRECATED
I've also attempted a straight suppression of every single error:
error_reporting = ~E_ALL
To no avail either. I've confirmed that it is correctly reading the php.ini file by adjusting other settings successfully.
I've also applied the error_reporting() function (with all different variations of what's provided above) within my scripts with no more luck. Does the location of the reporting have anything to do with the suppression? I've tried posting it at the top of the first file being loaded, also at the top of a required file that is getting called immediately upon executing the main script, no where does it seem to take it.
Try it with a number: http://www.php.net/manual/en/errorfunc.constants.php
Everything but the two deprecateds would be 8191.
PS. It's possible the app/framework/website you're watching/editing/creating sets the error reporting level to E_ALL. If so, it doesn't matter what you set in php.ini, because it's overridden later.
Related
in my php.ini the display_errors setting is set to Off by standard. Usually I started my index.php file with
ini_set('display_errors', 'On');
error_reporting(E_ALL & ~E_NOTICE);
which all worked fine for my needs.
Recently, the error reporting did not work anymore. notices have been thrown out though, so:
<?php echo $i ?>
throws a notice "undefined constant"
<?php badbadbad ?>
simply returns a blank page instead of a Fatal Error message.
Checking phpinfo() shows that the Master value for display_errors is Off, while the local value is set to On (as expected). Nevertheless I could not get any error message.
Changing my php.ini setting for display_errors = On gets me around this issue, but should not be a solution for ever.
Any hints?
Thanks & brgds
David
I think the reason your second example fails is that it's actually a Parse Error.
When executing code, PHP has to first parse and compile the whole file it's going to execute and then only after that it can run it. If there's a problem during parsing, even if the problem is at the end of the file, none of the file's code will be executed -- so neither will your ini_set() and error_reporting() statements.
If the erroneous code is in the same file as said statements, there's not much you can do. If it's in another file that is used with include or require, make sure that the including calls are made after setting the new error reporting values. At least that works for me with PHP >= 5.4.
I managed to run MongoDB on Codeigniter using Alex Bilbie` library. The operations go well (connection, queries etc. ) but sometimes I get these PHP notices:
Message: Mongo::__construct() [mongo.--construct]: localhost:27017: pool get (0x4bfab20)
Filename: libraries/Mongo_db.php
Line Number: 1274
A PHP Error was encountered
Severity: Notice
Message: Mongo::__construct() [mongo.--construct]: localhost:27017: found in pool (0x4bfab20)
Filename: libraries/Mongo_db.php
Is there a way to get rid of these? or maybe hide them..as they don't seem to mess up my pages in another way than splashing into the user's screen.
EDIT
On a few pages though, I use the JQgrid and when the errors show up they mess up my HTTP response and render some messy data.
The specific notice messages here have been removed in the MongoDB PHP driver 1.2.11 or later (see PHP-431). Upgrading your MongoDB driver to the latest should remove the excessive notice logging.
General notes on proper settings for Code Igniter logging in production still apply...
The E_NOTICE level of error reporting is intended to warn you about possible bugs or typos. It is typically only used as a development setting rather than for production messages.
The default error_reporting setting in PHP4 and PHP5 is actually set to ignore these:
E_ALL & ~E_NOTICE
The Code Igniter index.php has an application environment setting which normally shows all errors for development and suppresses error reporting for testing and production. You should set this appropriately:
define('ENVIRONMENT', 'production');
If you actually want to capture these messages for a production environment you should update the production settings in your index.php so that instead of error_reporting(0) you have:
error_reporting() set to appropriate level of detail
display_errors off
log_errors on
error_log path set
For example, in index.php you could have:
case 'production':
error_reporting(E_ALL);
ini_set('display_errors','Off');
ini_set('log_errors','On');
ini_set('error_log','/var/log/php5.log');
break;
That way the messages/notices will still be saved to the error_log if you want to review them, but they will not be shown to the end user.
Off the top of my head, there are a few things you could do. This is not an answer regarding a fix to the MongoDB error you are receveing, but rather regarding some methods in which you could hide the errors.
a) Use the '#' operator to ignore any error outputs from the method being called in which outputs the errors you are receiving. This would result in you renaming the method call to the following #method_outputting_mongodb_error($foo,$bar);.
b) Turn off error reporting in CodeIgniter. This is not the best method as all other errors will not be outputted.
There is a good link here re: how you can turn off error reporting: http://phpdog.blogspot.fr/2012/02/codeigniter-error-reporting-handling.html
As #Stennie mentions this has been fixed in later versions of the driver: https://jira.mongodb.org/browse/PHP-431
Try and upgrade.
Also this only existed on the Windows driver and only start happening after v1.2.1. I know that because the guy who made that JIRA also tried 1.2.1 on my advice and he didn't get those E_NOTICEs. I remember having the conversation that actually triggered that JIRA now :).
Unlike others I don't think you should "hide" these errors with E_ALL & ~E_NOTICE. No one is quite decided on hiding E_NOTICE however the general concensus is that it is not the best thing. Of course you would not want your logs to be filled with all this debug info about the MongoDB extension, instead the MongoDB extension should be silent (as you think it should).
Another reason I would not hide E_NOTICE is because of the php.ini of later versions of PHP:
; error_reporting
; Default Value: E_ALL & ~E_NOTICE
; Development Value: E_ALL | E_STRICT
; Production Value: E_ALL & ~E_DEPRECATED
By default PHP will actually install for Production Value (as it does for me) as such the default for PHP error reporting is:
E_ALL & ~E_DEPRECATED
This is the value I have for error_reporting on both my AWS and my local Ubuntu server 12.04 and I have not changed the values since installing as such the default value I gain from installing PHP from both repo and source is:
error_reporting = E_ALL & ~E_DEPRECATED
So the recommended default setup for production for later PHP versions (and probably future ones) actually shows E_NOTICE, which is useful but not if the logs are being filled with stuff from the Mongo extension.
Edit: Downvoter care to explain? I have basically given the same answer as #Stennie, why the downvote?
I have edited my answer to actually take the conversation in the comments on this answer and #Stennie's answer into consideration so the answer makes more sense now.
Sorted out this issue. Problem was the class file (and the folder, actually) was missing. Puzzled why with display_errors = On and E_ALL | E_STRICT defined (and Apache restarted), this would throw a white screen of death and not an error.
phpinfo() shows that the master value and the local value are the same, so I'm assuming that the error settings are not being overwritten somewhere in the code base (in an .htaccess or ini_set() call).
EDIT
The new object instantiation is here:
$type['content_object'] = new $type['handler_class']();
I also tried instantiating it without the variable, i.e. new Foo(); but still gave WSOD.
There might be an alternative error handler activated. Call restore_error_handler() prior to the line with the error (possibly multiple times) to reactivate PHP's default error handler.
I don't get any PHP error, just get a white page on Firefox, and
Server error
The website encountered an error while retrieving http://example.com/pruebas/prov.php. It may be down for maintenance or configured incorrectly
on Chrome.
This is the code:
if (!ini_get('display_errors')) {
ini_set('display_errors', 1);
}
echo "hola"
echo "hola2";
I intentionally made mistake in the echo "hola" (there's no ';').
I also tried adding to the end of my .htaccess file -> suPHP_ConfigPath /home/username/public_html replacing username with my current username, and then I created a php.ini in public_html with "display_errors = on;". But I'm still not able to get any PHP error.
Your script is dying due to the syntax error before it ever executes, so the ini_set() call is never executed and never takes effect. You'd have to change the setting in the appropriate php.ini.
The actual error message may be in a log file somewhere. Try Apache's error_log, or see if PHP's logging somewhere else.
Make sure that you also have the appropriate error_reporting ini value set as well. You can find more information on PHP.net
Set the error reporting level. The parameter is either an integer representing a bit field, or named constants. The error_reporting levels and constants are described in Predefined Constants, and in php.ini. To set at runtime, use the error_reporting() function. See also the display_errors directive.
In PHP 4 and PHP 5 the default value is E_ALL & ~E_NOTICE. This setting does not show E_NOTICE level errors. You may want to show them during development.
Source
Make sure the display_errors is set to on on your php.ini file.
In an action method, I have the following excerpt of code:
error_reporting(E_ALL);
ini_set('display_errors', '1');
Logger::log('test');
The Logger class is defined in this way:
class Logger {
public static function log() {
echo "test";
}
I deliberately forgot the closing brace of the function to demonstrate the problem. When the action is called, absolutely nothing is rendered on the screen. What type of error is this, and why is it not displayed, even though I configured PHP to show all errors, as shown above?
Of course, if I add the missing brace, everything is OK.
You also have to enable display_startup_errors to show Fatal errors:
Even when display_errors is on, errors that occur during PHP's startup sequence are not displayed. It's strongly recommended to keep display_startup_errors off, except for debugging.
Also see the Note for display_errors:
Although display_errors may be set at runtime (with ini_set()), it won't have any affect if the script has fatal errors. This is because the desired runtime action does not get executed.
You can set both values in Zend Framework's application.ini. On a sidenote: if you set error_reporting(-1) it will report (!display) all errors, including E_STRICT and any future additions.
I have exactly the same problem - I didn't manage to completely solve it, but I found out that all errors are correctly logged to a file, even though they are not displayed.
Just put this lines in your .htaccess/server config:
php_value log_errors On
php_value error_log "/path_to_logs/errors.log"