Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #18667
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: set_error_handler(): duplicate error |
| Date | 2021-06-20 13:10 +0200 |
| Message-ID | <ij8m13Fpc2cU1@mid.individual.net> (permalink) |
| References | (1 earlier) <iiu6nlForanU1@mid.individual.net> <sai4vp$11n3$1@gioia.aioe.org> <sajj55$jqj$1@jstuckle.eternal-september.org> <sakvm9$168h$1@gioia.aioe.org> <salu6v$qr1$1@jstuckle.eternal-september.org> |
Jerry Stuckle:
> 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. "
Thanks for pointing this out.
Also see: <https://www.php.net/manual/en/function.set-error-handler.php>
This means, if such an error ocurrs - like calling an undefined function
- it will *not* be passed to the handler defined in set_error_handler().
So this works:
------------------------------
<?php
set_error_handler(
function(
int $severity,
string $message,
string $file,
int $line
): void {
throw new Exception('Error catched: '.$message);
}
);
$a = 1/0;
------------------------------
But this *not*, because calling an undefined function will *not* be
passed to the user error handler:
<?php
set_error_handler(
function(
int $severity,
string $message,
string $file,
int $line
): void {
throw new Exception('Error catched: '.$message);
}
);
xxx();
--
Arno Welzel
https://arnowelzel.de
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
set_error_handler(): duplicate error alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-06-10 11:04 +0200
Re: set_error_handler(): duplicate error Ii Ii <ya12983@mail.com> - 2021-06-16 02:39 -0700
Re: set_error_handler(): duplicate error Arno Welzel <usenet@arnowelzel.de> - 2021-06-16 13:48 +0200
Re: set_error_handler(): duplicate error alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-06-18 14:53 +0200
Re: set_error_handler(): duplicate error Jerry Stuckle <jstucklex@attglobal.net> - 2021-06-18 22:00 -0400
Re: set_error_handler(): duplicate error alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-06-19 16:41 +0200
Re: set_error_handler(): duplicate error Jerry Stuckle <jstucklex@attglobal.net> - 2021-06-19 19:21 -0400
Re: set_error_handler(): duplicate error Arno Welzel <usenet@arnowelzel.de> - 2021-06-20 13:10 +0200
Re: set_error_handler(): duplicate error Arno Welzel <usenet@arnowelzel.de> - 2021-06-20 13:02 +0200
Re: set_error_handler(): duplicate error Arno Welzel <usenet@arnowelzel.de> - 2021-06-20 12:51 +0200
Re: set_error_handler(): duplicate error alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-06-21 17:06 +0200
Re: set_error_handler(): duplicate error Arno Welzel <usenet@arnowelzel.de> - 2021-06-21 19:43 +0200
Re: set_error_handler(): duplicate error alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-06-22 16:10 +0200
Re: set_error_handler(): duplicate error "J.O. Aho" <user@example.net> - 2021-06-22 18:13 +0200
Re: set_error_handler(): duplicate error alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-06-23 13:35 +0200
Re: set_error_handler(): duplicate error Arno Welzel <usenet@arnowelzel.de> - 2021-06-23 10:24 +0200
csiph-web