Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #18667

Re: set_error_handler(): duplicate error

Path csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Arno Welzel <usenet@arnowelzel.de>
Newsgroups comp.lang.php
Subject Re: set_error_handler(): duplicate error
Date Sun, 20 Jun 2021 13:10:28 +0200
Lines 87
Message-ID <ij8m13Fpc2cU1@mid.individual.net> (permalink)
References <s9ski4$42b$2@gioia.aioe.org> <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>
Mime-Version 1.0
Content-Type text/plain; charset=iso-8859-15
Content-Transfer-Encoding 8bit
X-Trace individual.net kvS+/4g5eOebn9eg9pC9DwyoNK/f8kxoEEbBGtUtWR0EIkXmK1
Cancel-Lock sha1:gj0qD+vVO5m+Cy2hvWWgsGC5sDc=
In-Reply-To <salu6v$qr1$1@jstuckle.eternal-september.org>
Xref csiph.com comp.lang.php:18667

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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