<?php
//error_reporting(0);
set_error_handler(
static function (int $severity, string $message, string $file, int
$line): void {
throw new InternalErrorException($message, 0, $severity, $file,
$line);
}
);
xxx();
Output:
Fatal error: Uncaught Error: Call to undefined function xxx() in /tmp/tmp.Ie1UVhkWcT/test.php on line 9
Error: Call to undefined function xxx() in /tmp/tmp.Ie1UVhkWcT/test.php
on line 9
Call Stack:
0.0001 392928 1. {main}() /tmp/tmp.Ie1UVhkWcT/test.php:0
Why error message showing is duplicate?
Furthermore, if uncommenting the error_reporting(0) instruction does not show any errors.
is there a good compromise?
<?php
//error_reporting(0);
set_error_handler(
static function (int $severity, string $message, string $file, int $line): void {
throw new InternalErrorException($message, 0, $severity, $file, $line);
}
);
xxx();
Output:
Fatal error: Uncaught Error: Call to undefined function xxx() in /tmp/tmp.Ie1UVhkWcT/test.php on line 9
Error: Call to undefined function xxx() in /tmp/tmp.Ie1UVhkWcT/test.php
on line 9
Call Stack:
0.0001 392928 1. {main}() /tmp/tmp.Ie1UVhkWcT/test.php:0
Why error message showing is duplicate?
I can't reproduce this.
When I run this script with PHP 7.4 as CLI, I
only get the expected result:
PHP Fatal error: Uncaught Error: Call to undefined function xxx() in D:\test-errorhandler.php:11
Stack trace:
#0 {main}
thrown in D:\test-errorhandler.php on line 11
Do you run the above script within a larger application which already
has some kind of error handling in place?
Il 16/06/21 13:48, Arno Welzel ha scritto:
I can't reproduce this.
????
When I run this script with PHP 7.4 as CLI, I
only get the expected result:
PHP Fatal error:� Uncaught Error: Call to undefined function xxx() in
D:\test-errorhandler.php:11
Stack trace:
#0 {main}
�� thrown in D:\test-errorhandler.php on line 11
Do you run the above script within a larger application which already
has some kind of error handling in place?
No.
$ php -v
PHP 7.4.3 (cli) (built: Oct� 6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
��� with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
��� with Xdebug v2.9.2, Copyright (c) 2002-2020, by Derick Rethans tmp.MLHFJ8krVq$ cat test.php
<?php
set_error_handler(
��� static function (int $severity, string $message, string $file, int $line): void {
������� throw new InternalErrorException($message, 0, $severity, $file, $line);
��� }
);
xxx();
tmp.MLHFJ8krVq$ php test.php
Fatal error: Uncaught Error: Call to undefined function xxx() in /tmp/tmp.MLHFJ8krVq/test.php on line 7
Error: Call to undefined function xxx() in /tmp/tmp.MLHFJ8krVq/test.php
on line 7
Call Stack:
��� 0.0001���� 394848�� 1. {main}() /tmp/tmp.MLHFJ8krVq/test.php:0
set_error_handler() requires a real function as its parameter, not
something dynamically defined.
Il 19/06/21 04:00, Jerry Stuckle ha scritto:
set_error_handler() requires a real function as its parameter, not
something dynamically defined.
class C {
��� static function f($severity, $message) {
������� throw new InternalErrorException($message);
��� }
}
set_error_handler('C::f');
xxx();
Output
Fatal error: Uncaught Error: Call to undefined function xxx() in /tmp/tmp.F06vf0Q7H0/test.php on line 10
Error: Call to undefined function xxx() in /tmp/tmp.F06vf0Q7H0/test.php
on line 10
Call Stack:
��� 0.0001���� 394552�� 1. {main}() /tmp/tmp.F06vf0Q7H0/test.php:0
set_error_handler() requires a real function as its parameter, not
something dynamically defined.
On 6/19/2021 10:41 AM, alex wrote:
Il 19/06/21 04:00, Jerry Stuckle ha scritto:
set_error_handler() requires a real function as its parameter, not
something dynamically defined.
class C {
��� static function f($severity, $message) {
������� throw new InternalErrorException($message);
��� }
}
set_error_handler('C::f');
xxx();
Output
Fatal error: Uncaught Error: Call to undefined function xxx() in
/tmp/tmp.F06vf0Q7H0/test.php on line 10
Error: Call to undefined function xxx() in /tmp/tmp.F06vf0Q7H0/test.php
on line 10
Call Stack:
��� 0.0001���� 394552�� 1. {main}() /tmp/tmp.F06vf0Q7H0/test.php:0
Normal operation. See the restrictions under set_error_handler(), namely
"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 independent of where they were
raised, and most of E_STRICT raised in the file where
set_error_handler() is called. "
Il 16/06/21 13:48, Arno Welzel ha scritto:
I can't reproduce this.
????
When I run this script with PHP 7.4 as CLI, I
only get the expected result:
PHP Fatal error: Uncaught Error: Call to undefined function xxx() in
D:\test-errorhandler.php:11
Stack trace:
#0 {main}
thrown in D:\test-errorhandler.php on line 11
Do you run the above script within a larger application which already
has some kind of error handling in place?
No.
$ php -v
PHP 7.4.3 (cli) (built: Oct 6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
with Xdebug v2.9.2, Copyright (c) 2002-2020, by Derick Rethans tmp.MLHFJ8krVq$ cat test.php
<?php
set_error_handler(
static function (int $severity, string $message, string $file, int $line): void {
throw new InternalErrorException($message, 0, $severity, $file, $line);
}
);
xxx();
tmp.MLHFJ8krVq$ php test.php
Fatal error: Uncaught Error: Call to undefined function xxx() in /tmp/tmp.MLHFJ8krVq/test.php on line 7
Error: Call to undefined function xxx() in /tmp/tmp.MLHFJ8krVq/test.php
on line 7
Call Stack:
0.0001 394848 1. {main}() /tmp/tmp.MLHFJ8krVq/test.php:0
So this is a local problem specific to your setup.
Il 20/06/21 12:51, Arno Welzel ha scritto:
So this is a local problem specific to your setup.
But I would like to understand what it is.
alex:
Il 20/06/21 12:51, Arno Welzel ha scritto:
So this is a local problem specific to your setup.
But I would like to understand what it is.
After playing around a bit with the code:
Propably because you have "display_errors = On" in your php.ini.
In my php.ini I have:
display_errors = Off
But when I change this to:
display_errors = On
Tada! Now I also get every error twice:
$ php error-test.php
PHP Fatal error: Uncaught Error: Call to undefined function xxx() in /home/arno/error-test.php:9
Stack trace:
#0 {main}
thrown in /home/arno/error-test.php on line 9
Fatal error: Uncaught Error: Call to undefined function xxx() in /home/arno/error-test.php:9
Stack trace:
#0 {main}
thrown in /home/arno/error-test.php on line 9
---------
And even if set_error_handler() will be used, it stays like this:
---------
$ php error-test.php
PHP Fatal error: Uncaught Exception: Error catched: Division by zero in /home/arno/error-test.php:4
Stack trace:
#0 /home/arno/error-test.php(8): {closure}()
#1 {main}
thrown in /home/arno/error-test.php on line 4
Fatal error: Uncaught Exception: Error catched: Division by zero in /home/arno/error-test.php:4
Stack trace:
#0 /home/arno/error-test.php(8): {closure}()
#1 {main}
thrown in /home/arno/error-test.php on line 4
---------
So my verdict: make sure you have "display_errors = Off" in your php.ini.
So as already mentioned (if no error handler is implemented) I can't see
any errors :|
Il 21/06/21 19:43, Arno Welzel ha scritto:[...]
So my verdict: make sure you have "display_errors = Off" in your php.ini.
So as already mentioned (if no error handler is implemented) I can't see
any errors :|
On 22/06/2021 16.10, alex wrote:
So as already mentioned (if no error handler is implemented) I can't
see any errors :|
php.ini:
error_log = syslog
if enabled, errors will be logged to the systems log system
example:
Jun 22 16:09:39 machine php: PHP Fatal error: Uncaught Error: Call to undefined function xx() in /tmp/a.php:2
Jun 22 16:09:39 machine php: Stack trace:
Jun 22 16:09:39 machine php: #0 {main}
Jun 22 16:09:39 machine php: thrown in /tmp/a.php on line 2
file in question:
<?php
xx();
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 151:42:55 |
| Calls: | 12,091 |
| Calls today: | 4 |
| Files: | 15,000 |
| Messages: | 6,517,607 |