Page 1 of 1
Error_Reporting Error
Posted: Fri Apr 16, 2010 5:23 pm
by lkenney
I'm new to php and am sure this is a simple problem. However, I cannot get any error reporting using the following code:
Code: Select all
<?php
error_reporting(E_ALL);
function test()
{
$foo = "Declared inside the function.
";
$bar = "Also declared inside the function.
";
return $bar;
}
$baz = test();
/*
* Notices are issued that $foo and $bar are undefined
*/
echo $foo, $bar, $baz;
?>
I am using Apache 2.2.15 and php 5.3.2
I
Any help will be appreciated.
Report to moderator 69.193.71.151
Re: Error_Reporting Error
Posted: Fri Apr 16, 2010 5:48 pm
by requinix
...What do you expect it to do? Or not do? The code's behaving exactly the way it should - you're getting the right error messages.
Re: Error_Reporting Error
Posted: Sat Apr 17, 2010 7:35 am
by JAY6390
Code: Select all
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
If you are trying to hide all errors, use
Re: Error_Reporting Error
Posted: Sat Apr 17, 2010 9:18 am
by lkenney
The post by JAY6390 solved the problem when I inserted it into the code. Do I need to change something in the php.ini file? Or, should I just insert his code into my files as I develop them? I am trying to teach myself php/mysql from books and online resources. I appreciate your help.
Re: Error_Reporting Error
Posted: Sat Apr 17, 2010 9:38 am
by JAY6390
I would personally have
in my php.ini file (I take it this is a local server or a server you have access to the php.ini file)
You could also do this wiht a .htaccess file in the root folder
Also be sure to restart your apache server once you've updated the php.ini file for changes to take effect
Re: Error_Reporting Error
Posted: Sat Apr 17, 2010 10:25 am
by lkenney
I have apache installed on my computer as well as php and am editing in Eclipse. I had gone into php.ini and changed error error reporting to on as seen here:
Code: Select all
; This directive controls whether or not and where PHP will output errors,
; notices and warnings too. Error output is very useful during development, but
; it could be very dangerous in production environments. Depending on the code
; which is triggering the error, sensitive information could potentially leak
; out of your application such as database usernames and passwords or worse.
; It's recommended that errors be logged on production servers rather than
; having the errors sent to STDOUT.
; Possible Values:
; Off = Do not display any errors
; stderr = Display errors to STDERR (affects only CGI/CLI binaries!)
; On or stdout = Display errors to STDOUT
; Default Value: On
; Development Value: On
; Production Value: Off
; http://php.net/display-errors
display_errors = On
However, I had not restarted Apache. So I restarted it and tried the code with the following line:
Code: Select all
ini_set('error_reporting', E_ALL);
No Joy.
So I reinserted the code you suggested earlier :
Code: Select all
ini_set('display_errors', 1);
error_reporting(E_ALL);
and it reported the errors correctly.
Are there any other lines in php.ini that need to be enabled or changed? Can you suggest a good resource for reference? I would really like to better understand how these files work . I didn't find the answers in the php info files or in the explanations within the php.ini file.
Again, Thanks for your assistance.