|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80670 error call exit in construct not run destruct
Submitted: 2021-01-25 21:26 UTC Modified: 2021-01-25 21:29 UTC
From: icarosnet at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 8.0Git-2021-01-25 (Git) OS: all
Private report: No CVE-ID: None
 [2021-01-25 21:26 UTC] icarosnet at gmail dot com
after few test; i try to migrate from php 7.4 to 8 and get that i think is a bug or you not documented it:

in php 7.4 when i run the constructor and inside it i run a exit(), the destructor will triggered.

in php 8.0 not; check this link example:

Work in php 7.4.13

not work in php 8.0

Test script:
//run in php 7.4.13 and php 8.0 you would see the diference.
class Test{
    function __construct(){
        echo '<div>Star Construct</div><br>';
    function __destruct(){
        echo '<div>Run Destruct</div><br>';
$t = new Test();


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-25 21:29 UTC]
-Status: Open +Status: Not a bug
 [2021-01-25 21:29 UTC]
This is explicitly mentioned in the migration guide (

> If an object constructor exit()s, the object destructor will no longer be called. This matches the behavior when the constructor throws.
 [2021-01-25 21:30 UTC]
I doubt this would be considered a bug. I would not expect the destructor to be run if the constructor has not completed, and would argue the change in behaviour was actually a bug fix.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Dec 07 19:03:40 2021 UTC