[php-src] Issue #20338: Fatal error: Uncaught Error: Maximum call stack size of 8306688 bytes (zend.max_allowed_stack_size - zend.reserved_stack_size)
reached. Infinite recursion? in 8.3.27 and 8.4.14
| From: | alexander-schranz | Date: | Thu, 30 Oct 2025 11:58:29 +0000 |
| Subject: | [php-src] Issue #20338: Fatal error: Uncaught Error: Maximum call stack size of 8306688 bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion? in 8.3.27 and 8.4.14 |
||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-251157@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/20338
Author: alexander-schranz
### Description
I'm fine if you close this issue as we found a way to workaround by implement serialization in
another way. Just want to report the issue here if it was unexpected change and / other stumble over
it they can get inspiration by our fix
[here](https://github.com/massiveart/MassiveSearchBundle/pull/186/files).
---
https://3v4l.org/40nda
The following code:
```php
<?php
/* Bridge between PHP versions */
trait SerializationHelper
{
/**
* @deprecated Use serializeToArray
*
* @return string
*/
public function serialize()
{
return serialize($this->serializeToArray());
}
/**
* @deprecated Use unserializeFromArray
*
* @param string $str
*
* @return void
*/
public function unserialize($str)
{
$this->unserializeFromArray(unserialize($str));
}
public function __serialize(): array
{
return [$this->serialize()];
}
public function __unserialize(array $data): void
{
$this->unserialize($data[0]);
}
}
class ClassMetadata implements \Serializable {
use SerializationHelper;
/**
* @var array
*/
private $indexMetadatas = [];
public function addIndexMetadata($contextName, IndexMetadata $indexMetadata)
{
$indexMetadata->setClassMetadata($this);
$this->indexMetadatas[$contextName] = $indexMetadata;
}
public function serializeToArray(): array
{
return [$this->indexMetadatas,];
}
public function unserializeFromArray(array $data): void
{
list($indexMetadata) = $data;
$this->indexMetadatas = $indexMetadata;
}
}
class IndexMetadata
{
/**
* @var ClassMetadata
*/
private $classMetadata;
public function getClassMetadata()
{
return $this->classMetadata;
}
public function setClassMetadata(ClassMetadata $classMetadata)
{
$this->classMetadata = $classMetadata;
}
}
$classMetadata = new ClassMetadata();
$indexMetadata = new IndexMetadata();
$classMetadata->addIndexMetadata('test', $indexMetadata);
var_dump(serialize($classMetadata));
```
Resulted in this output:
```
Fatal error: Uncaught Error: Maximum call stack size of 8306688 bytes (zend.max_allowed_stack_size -
zend.reserved_stack_size) reached. Infinite recursion? in /in/40nda:12
Stack trace:
```
But I expected this output instead:
```
string(175)
"O:13:"ClassMetadata":1:{i:0;s:137:"a:1:{i:0;a:1:{s:4:"test";O:13:"IndexMetadata":1:{s:28:"IndexMetadataclassMetadata";O:13:"ClassMetadata":1:{i:0;s:12:"a:1:{i:0;N;}";}}}}";}"
```
### PHP Version
```plain
PHP 8.3.27 (cli) (built: Oct 21 2025 14:53:41) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.27, Copyright (c) Zend Technologies
with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans
with Zend OPcache v8.3.27, Copyright (c), by Zend Technologies
```
### Operating System
MacOS:15.5, Ubuntu:latest, ...