Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Possibly missing warning for `unserialize('')` - may be confused with "false"

已关闭
#23,780 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
c, php
领域
backend

调研方向

Start by reproducing the supplied PHP example, then read ext/standard/var.c around php_unserialize_with_options at the linked condition. Check existing unserialize behavior and tests before deciding whether empty input should warn; done means the expected behavior is agreed and covered by an appropriate regression test.

由索引模型根据 Issue 内容生成。

描述

Bug Status: Verified
Description

The following code:

<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');

$a = 'b:0;'; // serialize(false);
$b = '';

var_dump($a === $b);
var_dump(unserialize($a) === unserialize($b));

Resulted in this output:

bool(false)
bool(true)

But I expected this output instead:

bool(false)

Warning: unserialize(): Empty input in /in/bjBq9 on line 11
bool(true)

Dear Developers, Artists,

Thank you for the marvel, art...

On 2026-09-18, at Libera IRC channel #php, a member ash_worksi raised this issue asking why no warning is raised in PHP, if compared to unserialize(' ');, for example.

My contention is the fact that it doesn't raise a warning like the description says. It's a very narrow edge case, but just like any "non-unserializable" string (...otherwise why would it return false?) it should raise the warning.

unserialize() returning false on it's own does not tell you whether the function failed to unserialize or if the value you unserialized was in fact false.

~ ash_worksi

Later, I tried searching for the actual reason it happens, and the condition involved is likely the following, in the function php_unserialize_with_options:

https://github.com/php/php-src/blob/13cec7c276033883e1e0ee22ea92fa1838b06dca/ext/standard/var.c#L1414-L1416

The condition explicitly checks if the string is empty, and returns "false" by design, and considering the first commits checked, it has been so for at least "20 years ago".

Image

I believe that for so much time, it was discussed already, but just in case, is it still actually expected?

Best and kind regards

PHP Version
PHP 8.5.10 (cli) (built: Sep 19 2026 00:23:53) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.5.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.10, Copyright (c), by Zend Technologies
Operating System

Kubuntu 26.10 (Docker)

主要语言
C
星标
40.4k
派生
8.2k
平均合并
2 天 17 小时
30 天内合并 PR
115

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

php/php-src 的其他 Issue

查看 php/php-src 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。