php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67319 Error with an infinite recursion in __toString().
Submitted: 2014-05-21 14:57 UTC Modified: 2014-05-21 16:52 UTC
From: Sysaninster at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.5.12 OS: centos 6.5
Private report: No CVE-ID: None
 [2014-05-21 14:57 UTC] Sysaninster at gmail dot com
Description:
------------
Error with an infinite recursion in __toString().

I get in CLI:
Segmentation fault

When I try execute this code in php-fpm, then I get an error in fpm log:
[21-May-2014 16:41:48] WARNING: [pool logic] child 8686 exited on signal 11 (SIGSEGV) after 957.896252 seconds from start

Test script:
---------------
class foo {
    public $parent = null;
    public function __toString() {
        return sprintf('some %s', $this->public);
    }
}

$test = new \foo();
$test->public = $test;
echo $test;

Expected result:
----------------
Fatal error: Maximum function nesting level of '500' reached, aborting! in /home
/sysanin/test.php on line 5

Call Stack:
    0.0002     118064   1. {main}() /home/sysanin/test.php:0
    0.0003     118372   2. foo->__toString() /home/sysanin/test.php:12
    0.0003     118428   3. sprintf() /home/sysanin/test.php:6
    0.0003     118720   4. foo->__toString() /home/sysanin/test.php:6
    0.0003     118776   5. sprintf() /home/sysanin/test.php:6
    0.0003     119068   6. foo->__toString() /home/sysanin/test.php:6
    0.0003     119136   7. sprintf() /home/sysanin/test.php:6
    0.0003     119428   8. foo->__toString() /home/sysanin/test.php:6
...
    0.0015     203708 493. sprintf() /home/sysanin/test.php:6
    0.0015     204000 494. foo->__toString() /home/sysanin/test.php:6
    0.0015     204056 495. sprintf() /home/sysanin/test.php:6
    0.0015     204348 496. foo->__toString() /home/sysanin/test.php:6
    0.0015     204404 497. sprintf() /home/sysanin/test.php:6
    0.0015     204696 498. foo->__toString() /home/sysanin/test.php:6
    0.0015     204752 499. sprintf() /home/sysanin/test.php:6



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-21 16:52 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 [2014-05-21 16:52 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is a stack overflow we can't detect in a good way. Only thin would be an arbitrary limit, which might be too low for some valid use cases on one machine but might be too high on a different machine.

Be careful with recursion.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 22:01:29 2024 UTC