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
 [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

Pull Requests

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 Dec 22 06:01:30 2024 UTC