|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-06-15 13:42 UTC] nikic@php.net
-Status: Open
+Status: Duplicate
[2016-06-15 13:42 UTC] nikic@php.net
[2016-06-15 14:00 UTC] brunocassol at gmail dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 12:00:01 2025 UTC |
Description: ------------ OSes: OSX (version 10.11.5), Ubuntu 14.04.3 LTS, CentOS release 6.5 (Final) PHP versions: 5.5, 5.6, 7.0 When implementing a simple singly linked list in PHP I get a segfault if I try to add too many items to the list. To define too many: the sample code attached could cope with 29,000 items on my machine but segfaults with 30,000 items. The interesting part is that if I first remove the items from the list, eg. with $this->head = $this->head->getNext() (method excluded from the sample code for brevity) then everything works as expected and I can add items to the list till it fill up and I get "Fatal error: Uncaught RuntimeException: Stack overflow.", which is expected. If I add __destruct() { $this->head = null; } to LinkedList and set a breakpoint there it will segfault when I execute that line. Test script: --------------- <?php class Node { private $next; public function setNext(Node $node = null) { $this->next = $node; return $this; } } class LinkedList { private $head; public function addNode() { $this->head = (new Node())->setNext($this->head); } } $ll = new LinkedList(); for ($i = 0; $i < 100000; $i++) { $ll->addNode(); } Expected result: ---------------- no output Actual result: -------------- 'php test.php' terminated by signal SIGSEGV (Address boundary error)