php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #79753 Fatal error can not be caught - not with catch nor error handler
Submitted: 2020-06-28 12:39 UTC Modified: 2020-07-05 10:46 UTC
From: michael dot vorisek at email dot cz Assigned:
Status: Suspended Package: Scripting Engine problem
PHP Version: Irrelevant OS: any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2020-06-28 12:39 UTC] michael dot vorisek at email dot cz
Description:
------------
see test code, there should be a possibility to catch these/all errors

Test script:
---------------
<?php

class A {
    public function x(): void {}
}

set_error_handler(function() { echo 'handled'; });

try {
    if (time() > 0) { // wrap in if to make sure an error is not throw at compile time
        class B extends A {
            public function x() {}
        }
    }
} catch (\Throwable $e) {
    echo 'catched';
}

Expected result:
----------------
"handled" or "catched"

Actual result:
--------------
fatal error message, no possibility to catch the error

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-30 14:57 UTC] cmb@php.net
-Type: Bug +Type: Feature/Change Request
 [2020-06-30 14:57 UTC] cmb@php.net
Well, that is not a bug; changing to feature request.

Note, though, that recovery isn't possible for all error cases.
In this case, it might be possible, but that's not trivial.
 [2020-07-05 10:38 UTC] michael dot vorisek at email dot cz
shutdown function is called when registered:
https://3v4l.org/FMoCK

so parse error should be possible to fix as the VM state is not corrupted
 [2020-07-05 10:46 UTC] nikic@php.net
-Status: Open +Status: Suspended
 [2020-07-05 10:46 UTC] nikic@php.net
The state is corrupted, e.g. both "new B" and "class B {}" inside the shutdown function will fail. The executor is not unstable, but it also does not satisfy the necessary consistency requirements to make it throw.

I'm suspending this to make it clear that we have no plans to convert this, or other inheritance errors, into exceptions in the near future.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Nov 25 09:01:23 2020 UTC