|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-01-19 21:05 UTC] eric at footsteps dot nl
[2005-01-19 22:13 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 12 13:00:01 2025 UTC |
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