ID: 31607 Updated by: [EMAIL PROTECTED] Reported By: denk at us dot es -Status: Open +Status: Bogus Bug Type: Output Control Operating System: Linux PHP Version: 4.3.10 New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php . Previous Comments: ------------------------------------------------------------------------ [2005-01-19 21:05:21] eric at footsteps dot nl 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. ------------------------------------------------------------------------ [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