note 61057 added to function.ob-start

From: Date: Tue, 24 Jan 2006 16:51:34 +0000
Subject: note 61057 added to function.ob-start
Groups: php.notes 
Request: Send a blank email to php-notes+get-102377@lists.php.net to get a copy of this message
Found that variables in class instances we're not being set after the call to ob_start(). Call ob_start after the variables are set however and it works but that didn't seem to solve the goal of a self contained templating class. The fix was to assign the class by reference with '&new' Here is a simplified working example: <?php class Buffer { var $template = ' - template set in class constructor'; function Buffer() { $this->startBuffer(); } function startBuffer() { ob_start(array(&$this, 'doFlush')); } function doFlush($buffer) { /* simple string concat to show use of a template string and the buffer output */ return $buffer . $this->template; } } /* template does not get set: $buffer1 = new Buffer(); $buffer1->template = ' - template set in instance'; echo 'some buffer content'; */ /* this works as expected */ $buffer2 = &new Buffer(); $buffer2->template = ' - template set in instance'; echo 'some buffer content'; ---- Server IP: 85.116.0.130 Probable Submitter: 80.3.64.8 (proxied: 86.11.186.120) ---- Manual Page -- http://www.php.net/manual/en/function.ob-start.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61057 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61057&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61057&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61057&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61057&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61057&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61057&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61057&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61057&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#102377) next »