[php-src] Issue #19082: unserialize() does not throw on non-array `allowed_classes` in PHP 8.4.0
| From: | ImperialCrise | Date: | Wed, 09 Jul 2025 19:25:33 +0000 |
| Subject: | [php-src] Issue #19082: unserialize() does not throw on non-array `allowed_classes` in PHP 8.4.0 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-250402@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/19082
Author: ImperialCrise
### Description
**Description:**
According to the PHP manual, as of PHP 8.4.0, passing a non-array value for the
allowed_classes option in unserialize() should trigger a
TypeError or ValueError. However, providing
['allowed_classes' => true] still silently reconstructs the object without
any exception.
---
**Steps to Reproduce:**
1. Create a file named test.php with the following contents:
```php
<?php
declare(strict_types=1);
class Person {
public string $name;
public int $age;
public function __construct(string $name, int $age) {
$this->name = $name;
$this->age = $age;
}
}
$serialized = serialize(new Person('Alice', 30));
$value = $serialized;
// Pass boolean instead of an array:
$result = unserialize($value, ['allowed_classes' => true]);
var_dump($result);
```
2. Run it from the command line:
```bash
php test.php
```
---
**Actual Result:**
```text
object(Person)#2 (2) {
["name"]=> string(5) "Alice"
["age"]=> int(30)
}
```
---
**Expected Result:**
A TypeError or ValueError should be thrown, for example:
```text
PHP Fatal error: Uncaught TypeError: unserialize(): "allowed_classes" option must be an
array of class names in ...
```
---
**Reference:**
PHP manual on unserialize() options (8.4.0):
https://www.php.net/manual/en/function.unserialize.php
### PHP Version
```plain
PHP 8.4.7 (cli) (built: May 9 2025 06:54:31) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.7, Copyright (c) Zend Technologies
with Zend OPcache v8.4.7, Copyright (c), by Zend Technologies
```
### Operating System
Ubuntu 24.04