Fibers still start with error_reporting = 0 when the directive is unset

未關閉
#25,249 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
73/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
c, php
領域
backend, testing

研究方向

Start with zend_fiber_execute() in Zend/zend_fibers.c and the error_reporting directive registration in Zend/zend.c; the issue traces how an unset directive becomes level 0. Read the existing gh23921.phpt test and check how the proposed child-process test runs PHP with -n. Done means a regression test covers the unset case and a fiber inherits the expected default level, 30719.

由索引模型根據 Issue 內容生成。

描述

Description

This is the case from #23921, which was closed by 3bb50c13a7a but still reproduces. When the error_reporting directive is unset, a fiber starts at level 0, so warnings raised inside it are silently dropped. The official Docker images load no php.ini by default, so there it happens without any flags.

The following code:

<?php
echo error_reporting(), "\n";
echo $main;
(new Fiber(function () {
    echo error_reporting(), "\n";
    echo $fiber;
}))->start();

Run with no flags on php:8.6-rc-cli-alpine. php -n gives the same levels.

Resulted in this output:

30719

Warning: Undefined variable $main in /in/test.php on line 3
0

But I expected this output instead, which is what 8.5.12 prints:

30719

Warning: Undefined variable $main in /in/test.php on line 3
30719

Warning: Undefined variable $fiber in /in/test.php on line 6

Setting the directive explicitly avoids the bug: with -d error_reporting=30719, 8.6 prints 30719 in both places.

Cause

zend_fiber_execute() reads zend_ini_long_literal("error_reporting") (Zend/zend_fibers.c:608). The directive is registered with a NULL default (Zend/zend.c:266), and zend_ini_long() returns 0 for a NULL value (Zend/zend_ini.c:468). 3bb50c13a7a removed the fallback to E_ALL that used to follow that read.

Line numbers are from PHP-8.6. master has the same code.

Why gh23921.phpt doesn't catch it

The test runs with the directive set, not unset. run-tests.php:274 passes error_reporting= with E_ALL to every test, and that is the value the test expects. So it passes with or without the bug:

Build gh23921.phpt under run-tests Fiber level with php -n
8.5.12 PASS 30719
8.6.0RC2, before 3bb50c13a7a PASS 0
8.6.0RC4, after 3bb50c13a7a PASS 0

--INI-- error_reporting= can't reach this case either. It sets an empty string rather than leaving the directive unset, and -d error_reporting= prints 0 0 on 8.5.12 too.

A test needs a child process started with -n. This one fails on RC2 and RC4 and passes on 8.5.12:

--TEST--
A fiber starts at the default error_reporting when the directive is unset
--FILE--
<?php
$code = <<<'PHP'
echo error_reporting(), "\n";
(new Fiber(function () {
    echo error_reporting(), "\n";
}))->start();
PHP;
echo shell_exec(escapeshellarg(getenv('TEST_PHP_EXECUTABLE')) . ' -n -r ' . escapeshellarg($code));
?>
--EXPECT--
30719
30719
PHP Version
PHP 8.6.0RC4 (cli) (built: Nov  5 2026 20:30:28) (ZTS)
Copyright © The PHP Group and Contributors
Built by https://github.com/docker-library/php
Zend Engine v4.6.0RC4, Copyright © Zend by Perforce
    with Zend OPcache v8.6.0RC4, Copyright ©, by Zend by Perforce

Also reproduced with php -n on 8.6.0RC5.

Operating System

Alpine Linux 3.24 (official Docker image, aarch64)

主要語言
C
星號
41.8k
分支
8.6k
平均合併
2 天 15 小時
30 天內合併 PR
125

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

php/php-src 的其他 Issue

查看 php/php-src 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。