|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46900 Unexpected behaviour in HEAD when output buffer callback returns null
Submitted: 2008-12-18 14:15 UTC Modified: 2008-12-28 20:08 UTC
From: robin_fernandes at uk dot ibm dot com Assigned: robinf (profile)
Status: Closed Package: Output Control
PHP Version: 6CVS-2008-12-18 (snap) OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: robin_fernandes at uk dot ibm dot com
New email:
PHP Version: OS:


 [2008-12-18 14:15 UTC] robin_fernandes at uk dot ibm dot com
In HEAD, the original input is sent to the output when the output buffer callback returns NULL. The docs for ob_start() only state this should happen when it returns FALSE - not NULL:

"If output_callback  returns FALSE original input is sent to the browser."

On PHP 5_2 and 5_3, the empty string is sent to the output when the output buffer callback returns NULL.

If the 5_2 & 5_3 behaviour is correct, here is a patch for HEAD :

Index: output.c
RCS file: /repository/php-src/main/output.c,v
retrieving revision 1.214
diff -u -w -p -r1.214 output.c
--- output.c	18 Aug 2008 07:45:59 -0000	1.214
+++ output.c	18 Dec 2008 14:08:53 -0000
@@ -983,7 +983,7 @@ static inline php_output_handler_status_
 			ZVAL_LONG(ob_mode, (long) context->op);
 			zend_fcall_info_argn(&handler->func.user->fci TSRMLS_CC, 2, &ob_data, &ob_mode);
-#define PHP_OUTPUT_USER_SUCCESS(retval) (retval && (Z_TYPE_P(retval) != IS_NULL) && (Z_TYPE_P(retval) != IS_BOOL || Z_BVAL_P(retval)))
+#define PHP_OUTPUT_USER_SUCCESS(retval) (retval && !(Z_TYPE_P(retval) == IS_BOOL && Z_BVAL_P(retval)==0))
 			if (SUCCESS == zend_fcall_info_call(&handler->func.user->fci, &handler->func.user->fcc, &retval, NULL TSRMLS_CC) && PHP_OUTPUT_USER_SUCCESS(retval)) {
 				/* user handler may have returned TRUE */

If HEAD's current behaviour is as intended, the docs should be updated to describe the new behaviour in PHP6.

Reproduce code:
function return_null($string) {
	return null;

echo "You shouldn't see this.\n";

echo 'done';

Expected result:

Actual result:
You shouldn't see this.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-24 19:50 UTC]
Commit it too. 

 [2008-12-28 20:08 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

I updated testcases ob_014.phpt and ob_015.phpt which relied the original behaviour.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Dec 03 10:05:54 2022 UTC