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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
15 + 23 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC