#31607 [Com]: ob_start with reference to $this fails
ID: 31607
Comment by: eric at footsteps dot nl
Reported By: denk at us dot es
Status: Open
Bug Type: Output Control
Operating System: Linux
PHP Version: 4.3.10
New Comment:
This behaviour is by design, for more information:
http://www.php.net/manual/en/language.oop.newref.php
this line
$page=& new HtmlPage('bar:');
would have the behaviour you seem to expect.
Previous Comments:
------------------------------------------------------------------------
[2005-01-19 11:07:03] denk at us dot es
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 this bug report at http://bugs.php.net/?id=31607&edit=1
Thread (3 messages)