php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33088 Output Buffering + Callback method = unable to change object properties
Submitted: 2005-05-21 02:10 UTC Modified: 2005-05-31 01:00 UTC
From: spam at cimmanon dot org Assigned:
Status: No Feedback Package: Output Control
PHP Version: 4.3.11 OS: OpenBSD
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: spam at cimmanon dot org
New email:
PHP Version: OS:

 

 [2005-05-21 02:10 UTC] spam at cimmanon dot org
Description:
------------
For some reason output buffering inside a callback method prevents an object's properties from being modified outside of the object.  Using output buffering without a callback works as expected, though.

Reproduce code:
---------------
<?
class foo {
	var $var = '';
	
	function foo() {
		$this->var = 'rar';
		print 'foo started<hr>';
		ob_start(array(&$this, 'bar'));
	}
	
	function bar() {
		print $this->var . "<br>";
		$this->var = 'asdf';
		print $this->var;
	}
}

$foo = new foo;
$foo->var = 'rarar';
?>

Expected result:
----------------
I expected $foo->var to be set to 'rarar' after the initial object creation via constructor, then 'asdf'.  Instead, it remains set to 'rar', then 'asdf'.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-22 15:34 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.

Please provide a more real-life example with expected and actual results.
 [2005-05-22 19:13 UTC] spam at cimmanon dot org
In the constructor, $this->var gets set to 'rar'.  Output buffering is started using foo::bar as the callback.  I attempt to set $this->var to 'rarar' from outside of the object, which fails because of the output buffering callback method.  The script finishes executing and the callback method is executed, prints $this->var (which is supposed to be set to 'rarar' at this point, but is still just 'rar'), sets $this->var to 'asdf' (successfully), then prints $this->var yet again.

If I attempt to print $foo->var right after I modify it on line #20, it displays exactly what I expect:  'rarar'.

This problem does not exist if I use a callback that is a function, nor does it happen if I start output buffering without a callback and just manually call foo::bar() at the end of the script.  Also, PHP 5 doesn't have this problem, for whatever reason, and performs exactly as I expect.

PHP 5.0.4:
http://www.sketchdiary.com/testcases/buffertest.php
http://www.sketchdiary.com/testcases/viewsource.php?file=buffertest.php

Modified source (forgot 1 line):
<?
class foo {
	var $var = '';
	
	function foo() {
		$this->var = 'rar';
		print 'foo started<hr>';
		ob_start(array(&$this, 'bar'));
	}
	
	function bar() {
		print $this->var . "<br>";
		$this->var = 'asdf';
		print $this->var;
		return ob_get_contents(); // missing line from example
	}
}

$foo = new foo;
$foo->var = 'rarar';
?>
 [2005-05-23 09:13 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-05-31 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 22:01:29 2024 UTC