Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

クローズ
#23,780 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
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日 12時間
マージ済み PR(30日)
112

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

php/php-src のほかの issue

php/php-src の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。