php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75509 Call "new static()" on __destruct will say segmentation fault
Submitted: 2017-11-10 08:07 UTC Modified: 2017-11-10 11:08 UTC
From: memory dot agape at gmail dot com Assigned:
Status: Duplicate Package: *General Issues
PHP Version: 7.1.11 OS: MacOS High Sierra
Private report: No CVE-ID: None
 [2017-11-10 08:07 UTC] memory dot agape at gmail dot com
Description:
------------
Call "new static()" on __destruct will say segmentation fault

-----
[1]    17385 segmentation fault  php test.php
-----

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

class A
{
    public function __destruct()
    {
        new static();
    }
}

new A();


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-11-10 08:13 UTC] sjon at hortensius dot net
this is not a bug - this is simple recursion. What did you expect would happen?
 [2017-11-10 11:04 UTC] memory dot agape at gmail dot com
I think to have to same expect "__construct"

Test Script:
---
<?php

class A
{
    public function __construct()
    {
        new static();
    }
}

new A();
----

Expect:
---
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in /path/to/test.php on line 7
---
 [2017-11-10 11:08 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2017-11-10 11:08 UTC] nikic@php.net
Duplicate of bug #64196 (for __clone, but the root issue is the same for all of these infinite recursion stack overflows).
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Apr 11 21:01:26 2021 UTC