8000 Deprecate returning non-string values from a user output handler by DanielEScherzer · Pull Request #18932 · php/php-src · GitHub
[go: up one dir, main page]

Skip to content

Deprecate returning non-string values from a user output handler #18932

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
merged 15 commits into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
context is also unavailable
  • Loading branch information
DanielEScherzer committed Jul 3, 2025
commit 470b7e990ae91fb35fb4e3e935aad944fc866d8b
27 changes: 13 additions & 14 deletions main/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -1035,12 +1035,15 @@ static inline php_output_handler_status_t php_output_handler_op(php_output_handl
OG(running) = NULL;
}

if (!still_have_handler) {
// Handler and context will have both already been freed
return status;
}

switch (status) {
case PHP_OUTPUT_HANDLER_FAILURE:
if (still_have_handler) {
/* disable this handler */
handler->flags |= PHP_OUTPUT_HANDLER_DISABLED;
}
/* disable this handler */
handler->flags |= PHP_OUTPUT_HANDLER_DISABLED;
/* discard any output */
if (context->out.data && context->out.free) {
efree(context->out.data);
Expand All @@ -1049,22 +1052,18 @@ static inline php_output_handler_status_t php_output_handler_op(php_output_handl
context->out.data = handler->buffer.data;
context->out.used = handler->buffer.used;
context->out.free = 1;
if (still_have_handler) {
handler->buffer.data = NULL;
handler->buffer.used = 0;
handler->buffer.size = 0;
}
handler->buffer.data = NULL;
handler->buffer.used = 0;
handler->buffer.size = 0;
break;
case PHP_OUTPUT_HANDLER_NO_DATA:
/* handler ate all */
php_output_context_reset(context);
ZEND_FALLTHROUGH;
case PHP_OUTPUT_HANDLER_SUCCESS:
if (still_have_handler) {
/* no more buffered data */
handler->buffer.used = 0;
handler->flags |= PHP_OUTPUT_HANDLER_PROCESSED;
}
/* no more buffered data */
handler->buffer.used = 0;
handler->flags |= PHP_OUTPUT_HANDLER_PROCESSED;
break;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
ob_start(): Check behaviour with deprecation when OOM triggers handler removal
ob_start(): Check behaviour with deprecation when OOM triggers handler removal (handler returns false)
--FILE--
<?php

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
ob_start(): Check behaviour with deprecation when OOM triggers handler removal (handler returns true)
--FILE--
<?php

ob_start(function() {
// We are out of memory, now trigger a deprecation
return true;
});

$a = [];
// trigger OOM in a resize operation
while (1) {
$a[] = 1;
}

?>
--EXPECTF--
Deprecated: main(): Returning a non-string result from user output handler Closure::__invoke is deprecated in %s on line %d

Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
ob_start(): Check behaviour with deprecation when OOM triggers handler removal (handler returns zero)
--FILE--
<?php

ob_start(function() {
// We are out of memory, now trigger a deprecation
return 0;
});

$a = [];
// trigger OOM in a resize operation
while (1) {
$a[] = 1;
}

?>
--EXPECTF--
Deprecated: main(): Returning a non-string result from user output handler Closure::__invoke is deprecated in %s on line %d

Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d
0