-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Deprecate producing output in a user output handler #19067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
DanielEScherzer
merged 4 commits into
php:master
from
DanielEScherzer:output-from-handler
Jul 10, 2025
+1,071
−16
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/output/ob_start_callback_bad_return/exception_handler.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/output/ob_start_callback_bad_return/exception_handler_nested.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
tests/output/ob_start_callback_output/exception_handler.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
--TEST-- | ||
ob_start(): Check behaviour with deprecation converted to exception [produce output] | ||
--FILE-- | ||
<?php | ||
|
||
$log = []; | ||
|
||
set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) { | ||
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); | ||
}); | ||
|
||
function first_handler($string) { | ||
global $log; | ||
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>"; | ||
echo __FUNCTION__; | ||
return "FIRST\n"; | ||
} | ||
|
||
function second_handler($string) { | ||
global $log; | ||
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>"; | ||
echo __FUNCTION__; | ||
return "SECOND\n"; | ||
} | ||
|
||
function third_handler($string) { | ||
global $log; | ||
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>"; | ||
echo __FUNCTION__; | ||
return "THIRD\n"; | ||
} | ||
|
||
$cases = [ | ||
'first_handler', | ||
'second_handler', | ||
'third_handler', | ||
]; | ||
foreach ($cases as $case) { | ||
$log = []; | ||
echo "\n\nTesting: $case\n"; | ||
ob_start($case); | ||
echo "Inside of $case\n"; | ||
try { | ||
ob_end_flush(); | ||
} catch (\ErrorException $e) { | ||
echo $e . "\n"; | ||
} | ||
echo "\nEnd of $case, log was:\n"; | ||
echo implode("\n", $log); | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Testing: first_handler | ||
FIRST | ||
ErrorException: ob_end_flush(): Producing output from user output handler first_handler is deprecated in %s:%d | ||
Stack trace: | ||
#0 [internal function]: {closure:%s:%d}(8192, 'ob_end_flush():...', %s, 41) | ||
#1 %s(%d): ob_end_flush() | ||
#2 {main} | ||
|
||
End of first_handler, log was: | ||
first_handler: <<<Inside of first_handler | ||
>>> | ||
|
||
Testing: second_handler | ||
SECOND | ||
ErrorException: ob_end_flush(): Producing output from user output handler second_handler is deprecated in %s:%d | ||
Stack trace: | ||
#0 [internal function]: {closure:%s:%d}(8192, 'ob_end_flush():...', %s, 41) | ||
#1 %s(%d): ob_end_flush() | ||
#2 {main} | ||
|
||
End of second_handler, log was: | ||
second_handler: <<<Inside of second_handler | ||
>>> | ||
|
||
Testing: third_handler | ||
THIRD | ||
ErrorException: ob_end_flush(): Producing output from user output handler third_handler is deprecated in %s:%d | ||
Stack trace: | ||
#0 [internal function]: {closure:%s:%d}(8192, 'ob_end_flush():...', %s, 41) | ||
#1 %s(%d): ob_end_flush() | ||
#2 {main} | ||
|
||
End of third_handler, log was: | ||
third_handler: <<<Inside of third_handler | ||
>>> |
82 changes: 82 additions & 0 deletions
82
tests/output/ob_start_callback_output/exception_handler_nested.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
--TEST-- | ||
ob_start(): Check behaviour with nested deprecation converted to exception [produce output] | ||
--FILE-- | ||
<?php | ||
|
||
$log = []; | ||
|
||
set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) { | ||
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); | ||
}); | ||
|
||
function first_handler($string) { | ||
global $log; | ||
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>"; | ||
echo __FUNCTION__; | ||
return "FIRST\n"; | ||
} | ||
|
||
function second_handler($string) { | ||
global $log; | ||
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>"; | ||
echo __FUNCTION__; | ||
return "SECOND\n"; | ||
} | ||
|
||
function third_handler($string) { | ||
global $log; | ||
$log[] = __FUNCTION__ . ": <<<" . $string . ">>>"; | ||
echo __FUNCTION__; | ||
return "THIRD\n"; | ||
} | ||
|
||
ob_start('first_handler'); | ||
ob_start('second_handler'); | ||
ob_start('third_handler'); | ||
|
||
echo "In all of them\n\n"; | ||
try { | ||
ob_end_flush(); | ||
} catch (\ErrorException $e) { | ||
echo $e->getMessage() . "\n"; | ||
} | ||
echo "Ended third_handler\n\n"; | ||
|
||
try { | ||
ob_end_flush(); | ||
} catch (\ErrorException $e) { | ||
echo $e->getMessage() . "\n"; | ||
} | ||
echo "Ended second_handler\n\n"; | ||
|
||
try { | ||
ob_end_flush(); | ||
} catch (\ErrorException $e) { | ||
echo $e->getMessage() . "\n"; | ||
} | ||
echo "Ended first_handler handler\n\n"; | ||
|
||
echo "All handlers are over\n\n"; | ||
echo implode("\n", $log); | ||
|
||
?> | ||
--EXPECT-- | ||
FIRST | ||
ob_end_flush(): Producing output from user output handler first_handler is deprecated | ||
Ended first_handler handler | ||
|
||
All handlers are over | ||
|
||
third_handler: <<<In all of them | ||
|
||
>>> | ||
second_handler: <<<THIRD | ||
ob_end_flush(): Producing output from user output handler third_handler is deprecated | ||
Ended third_handler | ||
|
||
>>> | ||
first_handler: <<<SECOND | ||
ob_end_flush(): Producing output from user output handler second_handler is deprecated | ||
Ended second_handler | ||
|
||
>>> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a little cleaner as
zend_string *handler_name = zend_string_copy(handler->name);