php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71480 __destruct documentation incorrect
Submitted: 2016-01-28 20:48 UTC Modified: 2016-01-28 21:56 UTC
From: bowersbros at gmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bowersbros at gmail dot com
New email:
PHP Version: OS:

 

 [2016-01-28 20:48 UTC] bowersbros at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/language.oop5.decon
---

> Attempting to throw an exception from a destructor (called in the time of script termination) causes a fatal error.

From the '__destruct()' section.

With this simple test script, I was not able to get it to throw an actual Fatal Error, but the Exception itself was thrown

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

class Testing {
    public function test() {
        return $this;
    }

    public function __destruct()
    {
        throw new \InvalidArgumentException();
    }
}

try {
    (new Testing())->test();
} catch (Exception $e) {
    echo 'Caught the exception';
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-28 21:56 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-01-28 21:56 UTC] requinix@php.net
In that code the destructor is called immediately because the object isn't being persisted anywhere and so it gets cleaned up on the spot. The docs are talking about something more like https://3v4l.org/QL4ie
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Dec 03 01:01:23 2020 UTC