php / php/php-src

ob handler should not print the output in case of callback exception

Open
#8,866 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?php

ob_start(function ($buffer) {
    // return '';
    throw new \Exception('x');
});

echo 5;

try {
    ob_flush();
} catch (\Exception $e) {
    echo $e;
}

Expected output:

-5Exception: x in /in/kQMfY:5
+Exception: x in /in/kQMfY:5
 Stack trace:
 #0 [internal function]: {closure}('5', 5)
 #1 /in/kQMfY(11): ob_flush()
 #2 {main}

https://3v4l.org/kQMfY

PHP Version

any

Operating System

any

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided PHP reproduction for ob_start and ob_flush, then compare its output with the expected output and the linked 3v4l example. Trace the output-buffer callback exception path in php-src and verify that the buffered value 5 is not printed when the callback throws; the work is done when this behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.