I have question. I have some app on facebook and getting this error
Fatal error: Uncaught OAuthException: An active access token must be used to query
information about the current user. thrown in
/home/xxx/public_html/domain/lib/base_facebook.php on line 1024
but no matter at this time.. the matter is that, is it possible to change/hide this "xxx" name? you understand? for example, instead this I would have /public_html/domain/...
OR completely hide the path ??
thanks in advance =)
The recommended action would be to disable the public display of all PHP errors when you are in production mode.
To do that, edit your php.ini file and set display_errors to 0. You can still set the error_reporting level to something suitable and all errors will be logged to the error_log file, but the actual errors themselves are not visible to the end user.
Otherwise, there is no way to modify PHP's built in error messages to hide the path. Doing so would render the error message much less helpful.
See display_errors and error_reporting PHP directives.
EDIT: In the case of the exact error message in your question, you could handle the error (try/catch) and then display a more friendly error that helps you but also doesn't expose your path. The reason it is displaying like that is because an exception that was thrown was uncaught.
No. If you don't want the complete debug backtrace in case of an uncaught exception, you'll need to catch it every time. There are no shortcuts here.
Related
I have a PHP REST API endpoint that throws an error:
PHP message: PHP Fatal error: Uncaught Exception: Accessing static property...as non static in...
with the default error_reporting value but returns a correct value if error_reporting is set to 1, which I believe is E_ERROR.
Doesn't error_reporting just control the logging? This seems to control whether the exception is thrown as well, allowing the code to continue as normal.
I come from a Java background, used to using Logback and similar logging frameworks. In these frameworks, the log level refers to a filter for the recipient of the logs, commonly a log file. A log level X means that messages need to be at least level X (or lower than, I forget which) to be logged, but it doesn't affect whether the exception is thrown to begin with.
I had assumed that this was the case with PHP's error_reporting, however, based on the above behavior I am not sure.
I've looked through the PHP docs, but I haven't found a detailed explanationof how error_reporting works
So, my question: What does "reporting" mean here? Does error_reporting control more besides which exceptions/errors are logged?
error_reporting is a bit different with the log level, the argument is a set of toggles for each error type.
For example error_reporting(E_ERROR) only reports errors and error_reporting(E_NOTICE) only reports notices and error_reporting(E_ERROR|E_NOTICE) reports both errors and notices but doesn't report warnings.
FYI the error level of this message "Accessing static property...as non static in..." is E_STRICT in PHP 5 and E_NOTICE in PHP 7 by default.
This is weired because you got an exception, I guess the problem that changes the behaviour of the error is in your error handler.
I am not sure how to pose this question. Sorry if this is already asked somewhere else: I want to log PHP errors on screen and warnings and above in a log file. Is there a way in PHP itself to set this or do I need to program a class as error handler that decides where to log?
You may want to use set_error_handler(). You can catch the level of an error, therefore decide whether to show up or log to file.
FYI, php error handling
I want to log some messages from my php application in the apache error logs. But I would like this to happen only in the non-production environments.
I found that php has error_log to log messages to the error log file but how do I control it to only log if my application is running in the non-prod environments.
Also, I found that there is trigger_error which takes a error type parameter. And the error_reporting setting in php.ini can then decide which error types are actually logged. So, while in dev, I have error_reporting set to E_ALL , it is more restricted in production. So, now I can use trigger_log and always log at E_USER_NOTICE. This would mean that my message is only shown in the dev log files but not in the production log files.
However, trigger_error also produces a stack trace with every log which is a bit unnecessary for me. How can I disable this stack trace.
Also, am I doing things the right way. How do people generally handle this problem.
Edit:
I am not trying to suppress error messages. I am trying to provide more debug messages in dev. Things like "Request came with following parameters", "step 1 done", etc. This is really not required in production.
If you want just custom messages sent into error log manually, log_error() is the function you are looking for.
Firstly, suppressing error handling is not a good idea - errors have a huge impact on your application performance - and suppressing error reporting does not eliminate the slowdown.
There is no 'trigger_log' in PHP.
The build in error handling in PHP does not generate a stack trace - you must have a custom error handler installed. You need to find it and amend the code if you want to change it's behaviour.
Using 'trigger_error' to record debug events is a very bad idea.
On my WordPress blog, whenever I have a PHP error, it breaks the site and displays a white page with the PHP error.
For example:
Parse error: syntax error, unexpected ';' in...
I can fix the error. However, I don't want users to see a broken site while I do. Is there a setting I can enable that will suppress the error (or more gracefully handle it) and continue to parse the rest of the PHP?
Sure: it's the setting whereby you don't make a parse error in your script. It's a setting in you.
(Parse errors generally can't be recovered from; what meaning does your script have if the parser cannot understand it? If it's not written in valid PHP? What do you want PHP to do?)
When you have a syntax error in a PHP page, it will always immediately stop parsing. It's the same thing as a compile error in languages such as C#, VB etc. There is no getting around this.
There are two ways you can suppress this error message. The first is with the error_reporting directive in your php.ini file. It's likely set to E_ALL & ~E_DEPRECATED. You can fine tune what is reported (via error logging and out to the display) by configuring the directives located on the PHP Site.
The other (simpler) way to suppress these is via the display_errors directive in your php.ini file. Simply set this to Off and restart your web server and you won't see these errors any longer - just a white page.
I want to know how I can display E_ERROR error messages to the screen but write E_ALL error messages to the error log, we currently use the error_reporting() in our app index page so we can change error reporting without the need to constantly restart the web server, but it seems that this (or perhaps the way it's meant to work) means that we only log errors that we see on the screen.
Is there a way to log and display different levels of errors?
Cheers!
You could make a custom error handler, and in your error handler check if the error is an E_ERROR; if so, print it out. Then log the error, regardless of whether it is an E_ERROR or not.
If you're not familiar with custom error handling, the PHP manual has a good example on how to use an error handler to do different things depending on the nature of a PHP error.