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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Only disable the problematic output handler
And update tests
  • Loading branch information
DanielEScherzer committed Jun 24, 2025
commit 340c7fdbe69a8cb31905db991fc0aadf12e10110
7 changes: 6 additions & 1 deletion Zend/tests/concat/bug79836.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ $c .= [];
ob_end_clean();
echo $counter . "\n";
?>
--EXPECT--
--EXPECTF--
Deprecated: main(): Returning a non-string result from user output handler Closure::__invoke is deprecated in %s on line %d

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

Deprecated: ob_end_clean(): Returning a non-string result from user output handler Closure::__invoke is deprecated in %s on line %d
3
5 changes: 4 additions & 1 deletion Zend/tests/concat/bug79836_1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ $x = $c . $x;
ob_end_clean();
echo "Done\n";
?>
--EXPECT--
--EXPECTF--
Deprecated: main(): Returning a non-string result from user output handler Closure::__invoke is deprecated in %s on line %d

Deprecated: ob_end_clean(): Returning a non-string result from user output handler Closure::__invoke is deprecated in %s on line %d
Done
5 changes: 4 additions & 1 deletion Zend/tests/concat/bug79836_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ $x = $c . $xxx;
ob_end_clean();
echo $x . "\n";
?>
--EXPECT--
--EXPECTF--
Deprecated: X::__toString(): Returning a non-string result from user output handler Closure::__invoke is deprecated in %s on line %d

Deprecated: ob_end_clean(): Returning a non-string result from user output handler Closure::__invoke is deprecated in %s on line %d
abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc
3 changes: 2 additions & 1 deletion Zend/tests/declare/gh18033_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ ob_start(function() {
);
});
?>
--EXPECT--
--EXPECTF--
Deprecated: PHP Request Shutdown: Returning a non-string result from user output handler Closure::__invoke is deprecated in %s on line %d
2 changes: 2 additions & 0 deletions Zend/tests/gh11189.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ while (1) {
?>
--EXPECTF--
Success
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 %s bytes exhausted%s(tried to allocate %s bytes) in %s on line %d
2 changes: 2 additions & 0 deletions Zend/tests/gh11189_1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ while (1) {
?>
--EXPECTF--
Success
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 %s bytes exhausted%s(tried to allocate %s bytes) in %s on line %d
7 changes: 6 additions & 1 deletion Zend/tests/gh16408.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ $c .= [];
ob_end_clean();
echo $counter . "\n";
?>
--EXPECT--
--EXPECTF--
Deprecated: main(): Returning a non-string result from user output handler Closure::__invoke is deprecated in %s on line %d

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

Deprecated: ob_end_clean(): Returning a non-string result from user output handler Closure::__invoke is deprecated in %s on line %d
3
3 changes: 2 additions & 1 deletion ext/session/tests/user_session_module/bug61728.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ class MySessionHandler implements SessionHandlerInterface {
session_set_save_handler(new MySessionHandler());
session_start();
?>
--EXPECT--
--EXPECTF--
Deprecated: ob_end_flush(): Returning a non-string result from user output handler output_html is deprecated in %s on line %d
8
8 changes: 4 additions & 4 deletions main/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -962,16 +962,16 @@ static inline php_output_handler_status_t php_output_handler_op(php_output_handl

if (SUCCESS == zend_call_function(&handler->func.user->fci, &handler->func.user->fcc) && Z_TYPE(retval) != IS_UNDEF) {
if (Z_TYPE(retval) != IS_STRING) {
// Make sure that we don't get lost in an output buffer
int old_flags = OG(flags);
OG(flags) = old_flags & (~PHP_OUTPUT_ACTIVATED);
// Make sure that we don't get lost in the current output buffer
// by disabling it
handler->flags |= PHP_OUTPUT_HANDLER_DISABLED;
php_error_docref(
NULL,
E_DEPRECATED,
"Returning a non-string result from user output handler %s is deprecated",
ZSTR_VAL(handler->name)
);
OG(flags) = old_flags;
handler->flags &= (~PHP_OUTPUT_HANDLER_DISABLED);
}
if (Z_TYPE(retval) == IS_FALSE) {
/* call failed, pass internal buffer along */
Expand Down
12 changes: 11 additions & 1 deletion sapi/cli/tests/gh8827-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,20 @@ print "STDOUT:\n";
fclose(STDOUT);
var_dump(@fopen('php://stdout', 'a'));
?>
--EXPECT--
--EXPECTF--
STDIN:

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

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

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

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

Deprecated: main(): Returning a non-string result from user output handler Closure::__invoke is deprecated in %s on line %d
bool(false)
9 changes: 5 additions & 4 deletions tests/output/ob_start_basic_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ foreach ($callbacks as $callback) {


--> Use callback 'return_false':
My output.
Deprecated: ob_end_flush(): Returning a non-string result from user output handler return_false is deprecated in %s on line %d

Deprecated: ob_end_flush(): Returning a non-string result from user output handler return_false is deprecated in %s on line %d
My output.

--> Use callback 'return_null':

Deprecated: ob_end_flush(): Returning a non-string result from user output handler return_null is deprecated in %s on line %d


Deprecated: ob_end_flush(): Returning a non-string result from user output handler return_null is deprecated in %s on line %d
--> Use callback 'return_string':
I stole your output.

--> Use callback 'return_zero':
0

Deprecated: ob_end_flush(): Returning a non-string result from user output handler return_zero is deprecated in %s on line %d
0
Loading