note 33857 added to function.ob-start
| From: | karlos at kastaneda dot kiev dot ua | Date: | Wed, 09 Jul 2003 13:59:03 +0000 |
| Subject: | note 33857 added to function.ob-start | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-51779@lists.php.net to get a copy of this message | ||
Using objects and output buffering, again...
In deed, you can ob_start() right from object's constructor.
Details: when (in PHP4) you execute something like
$object = new ClassName;
the object is 1) created, 2) copied to $object variable.
Of couse, using =& may help you to avoid 2).
Try this (it works, at least, at my PHP 4.3.2):
<?php
class myPage {
var $header;
function myPage() {
ob_start(array(&$this,"output"));
}
function output($raw_data) {
return "<h1>{$this->header}</h1>$raw_data";
}
}
$_page=&new myPage(); // note "=& new" ;-)
$_page->header="Some Header";
?>
...page contents
P.S. AFAIK in PHP5 this behavior will be changed. Any comments?
P.S.#2 Sorry for my worse English.
----
Manual Page -- http://www.php.net/manual/en/function.ob-start.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33857
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33857&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33857&report=yes