From: denk at us dot es
Operating system: Linux
PHP version: 4.3.10
PHP Bug Type: Output Control
Bug description: ob_start with reference to $this fails
Description:
------------
When executing the following script, output buffering is activated in the
constructor of HtmlPage, using a reference to $this. Php seems to create a
copy of the object at this moment, as subsequent changes to the object
(setting $page->title in the example) are not reflected in the output.
This example produces: "bar:Text". However, when we comment the call to
ob_start in the constructor and uncomment the call to ob_start using the
reference to $page in the main program, the code works as expected,
producing "foo:Text".
Reproduce code:
---------------
class HtmlPage {
var $title;
function HtmlPage($title='') {
$this->title=$title;
// starting ob here don't work
ob_start(array(&$this,'obuffer'));
}
function obuffer($buffer) {
return ($this->MakePageTop().$buffer);
}
function SetHtmlTitle($title) {
$this->title=$title;
}
function MakePageTop() {
return '<html><body>'.$this->title;
}
}
$page=new HtmlPage('bar:');
// when used here, it works as expected
// ob_start(array(&$page,'obuffer'));
echo 'Text<br>';
$page->title='foo:';
Expected result:
----------------
foo:Text
Actual result:
--------------
bar:Text
--
Edit bug report at http://bugs.php.net/?id=31607&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31607&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=31607&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=31607&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31607&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31607&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31607&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31607&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31607&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31607&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31607&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=31607&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=31607&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31607&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31607&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31607&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31607&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31607&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31607&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=31607&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31607&r=mysqlcfg