php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78031 __toString segmentation fault
Submitted: 2019-05-18 01:45 UTC Modified: 2019-05-18 08:13 UTC
From: gmblar+php at gmail dot com Assigned: cmb (profile)
Status: Duplicate Package: Scripting Engine problem
PHP Version: Irrelevant OS: macOS 10.14.5
Private report: No CVE-ID: None
 [2019-05-18 01:45 UTC] gmblar+php at gmail dot com
Description:
------------
PHP crashes with "Segmentation fault: 11" if you access $this->$this in __toString.

maybe related to:

* https://bugs.php.net/bug.php?id=53858
* https://bugs.php.net/bug.php?id=67319

https://3v4l.org/Rt2Qj/perf#output

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

class Foobar {
    
    public function __toString() {
        $this->$this;
    }

}

$foobar = new Foobar();
(string) $foobar;


Expected result:
----------------
no segmentation fault

Actual result:
--------------
Segmentation fault: 11

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-05-18 08:13 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Package: PDO related +Package: Scripting Engine problem -Assigned To: +Assigned To: cmb
 [2019-05-18 08:13 UTC] cmb@php.net
This is actually a duplicate of the mentioned tickets.  In this
case trying to convert the variable property name $this to string
calls Foobar::__toString() again, and so on, till the machine
stack is exhausted.

Note that we consider infinite recursion to be a userland
programming error.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Jan 20 16:01:24 2020 UTC