php / php/php-src

Issue with ob handler context and execution in PHP

Open
#13,965 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

I am encountering an issue while working with the "ob_start" function in PHP and the callback parameter.

Description:
When utilizing ob_start("system") to initiate output buffering with the "system" callback in the provided code snippet, I've observed that the zend_get_executed_filename function fails to return the correct file name when the "system" zend function is executed.

This discrepancy occurs particularly when a flush operation happens during php_request_shutdown.

<?php
ob_start("system");
?>

Observations:
Upon debugging, I've noticed the following:

  • Omission of the ob_flush() function call results in the flushing of output handlers during php_request_shutdown.
  • Prior to the invocation of php_output_end_all, the EG(current_execute_data) variable is set to NULL.
  • Consequently, when the "system" function is executed, it operates without the context of the current executed file name, leading to unexpected behavior.

Expected Behavior:
I expect the zend_get_executed_filename function to accurately retrieve the file name, even in scenarios involving flush operations during php_request_shutdown. Is this feasible?

PHP Version

PHP 8.3.3

Operating System

No response

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 tracing php_request_shutdown through php_output_end_all when ob_start("system") is used, and inspect how EG(current_execute_data) is handled before system calls zend_get_executed_filename. Reproduce the PHP 8.3.3 example with and without ob_flush(); done means the executed filename remains correct during shutdown flushing.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.