Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 1 addition & 7 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -361,16 +361,10 @@ PHP 8.5 UPGRADE NOTES
========================================

- Core:
. Returning a non-string from a user output handler is deprecated. The
deprecation warning will bypass the handler with the bad return to ensure
it is visible; if there are nested output handlers the next one will still
be used.
RFC: https://wiki.php.net/rfc/deprecations_php_8_4
. Trying to produce output (e.g. with `echo`) within a user output handler
is deprecated. The deprecation warning will bypass the handler producing the
output to ensure it is visible; if there are nested output handlers the next
one will still be used. If a user output handler returns a non-string and
produces output, the warning about producing an output is emitted first.
one will still be used.
RFC: https://wiki.php.net/rfc/deprecations_php_8_4
. Non-canonical cast names (boolean), (integer), (double), and (binary) have
been deprecated, use (bool), (int), (float), and (string) respectively.
Expand Down
21 changes: 2 additions & 19 deletions main/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,6 @@ static inline php_output_handler_status_t php_output_handler_op(php_output_handl
if (handler->flags & PHP_OUTPUT_HANDLER_USER) {
zval ob_args[2];
zval retval;
ZVAL_UNDEF(&retval);

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

if (SUCCESS == zend_call_function(&handler->func.user->fci, &handler->func.user->fcc) && Z_TYPE(retval) != IS_UNDEF) {
if (Z_TYPE(retval) != IS_STRING || handler->flags & PHP_OUTPUT_HANDLER_PRODUCED_OUTPUT) {
if (handler->flags & PHP_OUTPUT_HANDLER_PRODUCED_OUTPUT) {
// Make sure that we don't get lost in the current output buffer
// by disabling it
handler->flags |= PHP_OUTPUT_HANDLER_DISABLED;
// Make sure we keep a reference to the handler name in
// case
// * The handler produced output *and* returned a non-string
// * The first deprecation message causes the handler to
// be removed
zend_string *handler_name = handler->name;
zend_string_addref(handler_name);
if (handler->flags & PHP_OUTPUT_HANDLER_PRODUCED_OUTPUT) {
// The handler might not always produce output
handler->flags &= ~PHP_OUTPUT_HANDLER_PRODUCED_OUTPUT;
php_error_docref(
NULL,
E_DEPRECATED,
"Producing output from user output handler %s is deprecated",
ZSTR_VAL(handler_name)
);
}
if (Z_TYPE(retval) != IS_STRING) {
php_error_docref(
NULL,
E_DEPRECATED,
"Returning a non-string result from user output handler %s is deprecated",
ZSTR_VAL(handler_name)
ZSTR_VAL(handler->name)
);
}
zend_string_release(handler_name);

// Check if the handler is still in the list of handlers to
// determine if the PHP_OUTPUT_HANDLER_DISABLED flag can
Expand Down
9 changes: 2 additions & 7 deletions tests/output/ob_start_basic_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,19 @@ foreach ($callbacks as $callback) {
}

?>
--EXPECTF--
--EXPECT--
--> Use callback 'return_empty_string':


--> Use callback 'return_false':

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


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

--> Use callback 'return_zero':

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

147 changes: 0 additions & 147 deletions tests/output/ob_start_callback_bad_return/exception_handler.phpt

This file was deleted.

This file was deleted.

Loading