Bug #80670 [Com]: error call exit in construct not run destruct
| From: | daverandom@php.net | Date: | Mon, 25 Jan 2021 21:30:11 +0000 |
| Subject: | Bug #80670 [Com]: error call exit in construct not run destruct | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-231771@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80670&edit=1
ID: 80670
Comment by: daverandom@php.net
Reported by: icarosnet at gmail dot com
Summary: error call exit in construct not run destruct
Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: all
PHP Version: 8.0Git-2021-01-25 (Git)
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2021-01-25 21:29:31] nikic@php.net
This is explicitly mentioned in the migration guide
(https://www.php.net/manual/en/migration80.incompatible.php):
> 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:26:26] icarosnet at gmail dot com
Description:
------------
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
http://sandbox.onlinephpfunctions.com/code/38f312d12f72cba32c3cd1819a047504b0d62f6c
not work in php 8.0
http://sandbox.onlinephpfunctions.com/code/38f312d12f72cba32c3cd1819a047504b0d62f6c
Test script:
---------------
<?php
//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>';
if(true){
exit();
}
}
function __destruct(){
echo '<div>Run Destruct</div><br>';
}
}
$t = new Test();
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80670&edit=1