php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42200 when ob_start meet the internal functions..
Submitted: 2007-08-03 11:30 UTC Modified: 2007-08-12 01:00 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: roast@php.net Assigned:
Status: No Feedback Package: Output Control
PHP Version: 5.2.4RC1 OS: windows xp sp2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: roast@php.net
New email:
PHP Version: OS:

 

 [2007-08-03 11:30 UTC] roast@php.net
Description:
------------
I use the functions ob_* with the internal functions to control the output,but in reality, things always happen out of expectation.

Reproduce code:
---------------
<?php
ob_start('md5');
echo "roast is a good boy";
echo ob_get_contents();
?>

Expected result:
----------------
e21b1aad689c47aeac5b7867c2c77afa

Actual result:
--------------
A&#29780;&#65533;&#57535;&#65533;)&#65533;

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-04 14:02 UTC] jani@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.



 [2007-08-12 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2023-12-24 22:25 UTC] haszika80 at gmail dot com
This is/was not a bug. The sample code had two fundamental issues:

1. as the buffer was not flushed before that line, the string returned by ob_get_contents() ('roast is a good boy') was passed to the output handler (md5) twice as the buffer was flushed at the end of the script

2. md5 expects two parameters to which OB passed the buffer contents and an int representing the OB context op. This int was interpreted by md5 as a bool true and hence the binary return value

The following code achieves what OP wanted:

<?php
function md5Proxy($buffer, $phase) {
    return md5($buffer);
};

ob_start('md5Proxy');
echo 'roast is a good boy';
ob_end_flush();
?>

Result:
-------
e21b1aad689c47aeac5b7867c2c77afa
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 07:01:32 2024 UTC