473,385 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problems with set_error_handler() :/

Hi !
It's my first post here: Hello everyone :-)
Do you know why this code doesnt work ? Thanks for any help.

<?
echo('start<br>');
// redefine the user error constants - PHP 4 only
define("FATAL", E_USER_ERROR);
define("ERROR", E_USER_WARNING);
define("WARNING", E_USER_NOTICE);

// set the error reporting level for this script
error_reporting(FATAL | ERROR | WARNING);
echo('test<br>');
function catch_err($errno, $errstr,$errfile, $errline)
{
echo "<b>FATAL</b> [$errno] $errstr<br />\n";
echo('error!');
}
set_error_handler("catch_err", E_ERROR);

trigger_error("test...", E_USER_ERROR);
echo('<br>end');
?>

--
zYm3N[@interia.pl]

..:: C++ | C | PHP | HTML | Delphi | Pascal
..:: >> http://zymen.cjb.net <<
..:: http://zymen.cjb.net/cytowanie.html
Jul 17 '05 #1
7 5219
On Sun, 1 Aug 2004 14:43:07 +0200, zYm3N <zy***@interia.pl> wrote:
Hi !
It's my first post here: Hello everyone :-)
Do you know why this code doesnt work ? Thanks for any help.

<?
echo('start<br>');
// redefine the user error constants - PHP 4 only
define("FATAL", E_USER_ERROR);
define("ERROR", E_USER_WARNING);
define("WARNING", E_USER_NOTICE);

// set the error reporting level for this script
error_reporting(FATAL | ERROR | WARNING);
You've just turne off all the usual PHP errors, and only set it to use
user-level errors. It's pretty clear why you've done this, but it's masked a
problem a bit further down...
echo('test<br>');
function catch_err($errno, $errstr,$errfile, $errline)
{
echo "<b>FATAL</b> [$errno] $errstr<br />\n";
echo('error!');
}
set_error_handler("catch_err", E_ERROR);
After commenting out the error_reporting call further up, it reveals the
actual problem:

Warning: Wrong parameter count for set_error_handler() in
/home/andyh/public_html/test.php on line 16

See:
http://uk2.php.net/manual/en/functio...or-handler.php

You haven't said what version of PHP you're on, but the second argument only
exists in PHP5, not PHP4.

Because of this it probably hasn't installed the error handler.
trigger_error("test...", E_USER_ERROR);
echo('<br>end');
?>


After changing the set_error_handler line to set_error_handler("catch_err") I
get:

start
test
FATAL [256] test...
error!
end

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #2
Dnia Sun, 01 Aug 2004 13:58:52 +0100, Andy Hassall spłodził(a):
http://uk2.php.net/manual/en/functio...or-handler.php

I read it once again.. And I found something interesting:

"Note: The following error types cannot be handled with a user defined
function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR,
E_COMPILE_WARNING, and E_STRICT."

Now my code looks like:
<?
echo('start<br>');
error_reporting(E_ALL);
echo($_SERVER["SERVER_SOFTWARE"]);

function catch_error($errno, $errstr, $errfile, $errline)
{
echo('<br>error<br>');
}

set_error_handler('catch_error');

trigger_error("Cannot divide by zero", E_USER_ERROR); //there my function
works fine..

$a->out("it can't work"); //there is an error too!,
//and now I know, why isn't it catch by my function..
echo('start<br>');
?>

The code above produces:
"
start
Apache/1.3.29 (Win32) mod_gzip/1.3.26.1a PHP/4.3.4
error

Fatal error: Call to a member function on a non-object in
c:\usr\apache\httpd\html\p\error.php on line 15
"

Thanks for help.. Now it is a bit easier for me.

--
zYm3N[@interia.pl]

..:: C++ | C | PHP | HTML | Delphi | Pascal
..:: >> http://zymen.cjb.net <<
..:: http://zymen.cjb.net/cytowanie.html
Jul 17 '05 #3
Andy Hassall wrote:
Hi !
It's my first post here: Hello everyone :-)
Do you know why this code doesnt work ? Thanks for any help.

<?
echo('start<br>');
// redefine the user error constants - PHP 4 only
define("FATAL", E_USER_ERROR);
define("ERROR", E_USER_WARNING);
define("WARNING", E_USER_NOTICE);

// set the error reporting level for this script
error_reporting(FATAL | ERROR | WARNING);


If i may add a comment to what Andy just said:

Don't use parentheses for echo and print. As it is not a function, those
aren't needed, and you'll save yourself a good deal of pain when you'll
be adding more than one argument to what you're printing/echoing on screen.

Regards,
Sebastian
Jul 17 '05 #4
Dnia Sun, 01 Aug 2004 15:36:44 +0200, Sebastian Lauwers spłodził(a):
Don't use parentheses for echo and print. As it is not a function, those
aren't needed, and you'll save yourself a good deal of pain when you'll
be adding more than one argument to what you're printing/echoing on screen.


Can You give me an example ? I dont understand, what you really mean.
--
zYm3N[@interia.pl]

..:: C++ | C | PHP | HTML | Delphi | Pascal
..:: >> http://zymen.cjb.net <<
..:: http://zymen.cjb.net/cytowanie.html
Jul 17 '05 #5
Look at this article for another approach -
http://www.tonymarston.co.uk/php-mys...orhandler.html

--
Tony Marston

http://www.tonymarston.net
"zYm3N" <zy***@interia.pl> wrote in message
news:6i***************************@40tude.net...
Dnia Sun, 01 Aug 2004 13:58:52 +0100, Andy Hassall spłodził(a):
http://uk2.php.net/manual/en/functio...or-handler.php I read it once again.. And I found something interesting:

"Note: The following error types cannot be handled with a user defined
function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR,
E_COMPILE_WARNING, and E_STRICT."

Now my code looks like:
<?
echo('start<br>');
error_reporting(E_ALL);
echo($_SERVER["SERVER_SOFTWARE"]);

function catch_error($errno, $errstr, $errfile, $errline)
{
echo('<br>error<br>');
}

set_error_handler('catch_error');

trigger_error("Cannot divide by zero", E_USER_ERROR); //there my function
works fine..

$a->out("it can't work"); //there is an error too!,
//and now I know, why isn't it catch by my

function.. echo('start<br>');
?>

The code above produces:
"
start
Apache/1.3.29 (Win32) mod_gzip/1.3.26.1a PHP/4.3.4
error

Fatal error: Call to a member function on a non-object in
c:\usr\apache\httpd\html\p\error.php on line 15
"

Thanks for help.. Now it is a bit easier for me.

--
zYm3N[@interia.pl]

.:: C++ | C | PHP | HTML | Delphi | Pascal
.:: >> http://zymen.cjb.net <<
.:: http://zymen.cjb.net/cytowanie.html

Jul 17 '05 #6
On Sun, 1 Aug 2004 15:48:19 +0200, zYm3N <zy***@interia.pl> wrote:

Can You give me an example ? I dont understand, what you really mean.


echo 'No parenthesis needed for this error!';

Jul 17 '05 #7
zYm3N <zy***@interia.pl> wrote in message news:<6i***************************@40tude.net>...
http://uk2.php.net/manual/en/functio...or-handler.php I read it once again.. And I found something interesting:

"Note: The following error types cannot be handled with a user defined
function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR,
E_COMPILE_WARNING, and E_STRICT."


You can catch E_ERROR (fatal) errors with output buffering
<http://www.google.com/search?q=cache:ru2.php.net/set_error_handler#35622>

To catch all errors you may want to try
<http://www.phpclasses.org/logwatcher> as they use JavaScript
solutions.
Now my code looks like:
<?
echo('start<br>');
error_reporting(E_ALL);


AFAIK, error_reporting() will have no effects if custom error
handler is enabled.

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JohnVT | last post by:
Hi. I mentioned this before, but I think my question got kind of lost. I'll make it one short question now. With set_error_handler('myErrorHandler') I bypass PHP's standard error handler,...
5
by: lawrence | last post by:
If I call this function at the top of the page, does that mean that the function sendErrorsPhpToPds() is now called everytime there is an error? Does this still work if I also go...
14
by: Jim Hubbard | last post by:
Are you up to speed on the difficulties in using the 1.1 .Net framework? Not if you are unaware of the 1,596 issues listed at KBAlertz (http://www.kbalertz.com/technology_3.aspx). If you are...
1
by: 3f | last post by:
Hello; We have made a web application that people can download from our web site and installed on: Windows XP Windows 2000 Professional Windows 2003 Server Windows 2000 Server
5
by: Corky | last post by:
This works: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS INNER JOIN PROBLEMS ON PROBLEM_OBJECTS.PROBLEM_ID = PROBLEMS.PROBLEM_ID WHERE INTEGER(DAYS(CURRENT DATE) -...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
0
by: Sergistm | last post by:
Hello World, :D I have a problem that it is making me crazy, I hope you can help me. I'm trying to execute a .exe file with the Procces.Start, and there is no problem when the file is on my...
3
by: Taras_96 | last post by:
Hi everyone, In the documentation it says that set_error_handler will return 'Returns a string containing the previously defined error handler (if any), or NULL on error.' However, in my...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.