[php-src] Issue #7749: Segfault when recursive call is made
| From: | noreply@php.net | Date: | Sat, 11 Dec 2021 15:18:13 +0000 |
| Subject: | [php-src] Issue #7749: Segfault when recursive call is made | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-238335@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7749
Comment Author: mvorisek
```
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'on');
class Product {
private array $groups = [];
public function addGroup(Group $group): void {
$group->addProduct($this);
$this->groups[] = $group;
}
}
class Group {
private array $products = [];
public function addProduct(Product $product): void {
static $counter;
$counter++;
if (($counter % 1000_000) === 0) {
var_dump(($counter / 1000_000) . ' M');
}
$product->addGroup($this);
$this->products[] = $product;
}
}
$product = new Product();
$group = new Group();
$product->addGroup($group);
```
what is the last
$counter printed? I tried to run it on PHP 7.4 on linux & Win with
4GB memory limit and it resulted in Fatal error: Allowed memory size with
$counter 14 M, eg. more than 14 millions nested calls.