Skip to content

Commit 2711864

Browse files
Revert "Deprecate returning non-string values from a user output handler (#18932)" (#20455)
This partially reverts commit d8577d9, and reverts parts of 07f1cfd.
1 parent 7a96a68 commit 2711864

19 files changed

+5
-1123
lines changed

UPGRADING

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,16 +361,10 @@ PHP 8.5 UPGRADE NOTES
361361
========================================
362362

363363
- Core:
364-
. Returning a non-string from a user output handler is deprecated. The
365-
deprecation warning will bypass the handler with the bad return to ensure
366-
it is visible; if there are nested output handlers the next one will still
367-
be used.
368-
RFC: https://wiki.php.net/rfc/deprecations_php_8_4
369364
. Trying to produce output (e.g. with `echo`) within a user output handler
370365
is deprecated. The deprecation warning will bypass the handler producing the
371366
output to ensure it is visible; if there are nested output handlers the next
372-
one will still be used. If a user output handler returns a non-string and
373-
produces output, the warning about producing an output is emitted first.
367+
one will still be used.
374368
RFC: https://wiki.php.net/rfc/deprecations_php_8_4
375369
. Non-canonical cast names (boolean), (integer), (double), and (binary) have
376370
been deprecated, use (bool), (int), (float), and (string) respectively.

main/output.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,6 @@ static inline php_output_handler_status_t php_output_handler_op(php_output_handl
956956
if (handler->flags & PHP_OUTPUT_HANDLER_USER) {
957957
zval ob_args[2];
958958
zval retval;
959-
ZVAL_UNDEF(&retval);
960959

961960
/* ob_data */
962961
ZVAL_STRINGL(&ob_args[0], handler->buffer.data, handler->buffer.used);
@@ -969,36 +968,20 @@ static inline php_output_handler_status_t php_output_handler_op(php_output_handl
969968
handler->func.user->fci.retval = &retval;
970969

971970
if (SUCCESS == zend_call_function(&handler->func.user->fci, &handler->func.user->fcc) && Z_TYPE(retval) != IS_UNDEF) {
972-
if (Z_TYPE(retval) != IS_STRING || handler->flags & PHP_OUTPUT_HANDLER_PRODUCED_OUTPUT) {
971+
if (handler->flags & PHP_OUTPUT_HANDLER_PRODUCED_OUTPUT) {
973972
// Make sure that we don't get lost in the current output buffer
974973
// by disabling it
975974
handler->flags |= PHP_OUTPUT_HANDLER_DISABLED;
976-
// Make sure we keep a reference to the handler name in
977-
// case
978-
// * The handler produced output *and* returned a non-string
979-
// * The first deprecation message causes the handler to
980-
// be removed
981-
zend_string *handler_name = handler->name;
982-
zend_string_addref(handler_name);
983975
if (handler->flags & PHP_OUTPUT_HANDLER_PRODUCED_OUTPUT) {
984976
// The handler might not always produce output
985977
handler->flags &= ~PHP_OUTPUT_HANDLER_PRODUCED_OUTPUT;
986978
php_error_docref(
987979
NULL,
988980
E_DEPRECATED,
989981
"Producing output from user output handler %s is deprecated",
990-
ZSTR_VAL(handler_name)
991-
);
992-
}
993-
if (Z_TYPE(retval) != IS_STRING) {
994-
php_error_docref(
995-
NULL,
996-
E_DEPRECATED,
997-
"Returning a non-string result from user output handler %s is deprecated",
998-
ZSTR_VAL(handler_name)
982+
ZSTR_VAL(handler->name)
999983
);
1000984
}
1001-
zend_string_release(handler_name);
1002985

1003986
// Check if the handler is still in the list of handlers to
1004987
// determine if the PHP_OUTPUT_HANDLER_DISABLED flag can

tests/output/ob_start_basic_002.phpt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,19 @@ foreach ($callbacks as $callback) {
3535
}
3636

3737
?>
38-
--EXPECTF--
38+
--EXPECT--
3939
--> Use callback 'return_empty_string':
4040

4141

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

4745
--> Use callback 'return_null':
4846

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

5248
--> Use callback 'return_string':
5349
I stole your output.
5450

5551
--> Use callback 'return_zero':
56-
57-
Deprecated: ob_end_flush(): Returning a non-string result from user output handler return_zero is deprecated in %s on line %d
5852
0
53+

tests/output/ob_start_callback_bad_return/exception_handler.phpt

Lines changed: 0 additions & 147 deletions
This file was deleted.

tests/output/ob_start_callback_bad_return/exception_handler_nested.phpt

Lines changed: 0 additions & 143 deletions
This file was deleted.

0 commit comments

Comments
 (0)