ID: 33088 User updated by: spam at cimmanon dot org Reported By: spam at cimmanon dot org -Status: Feedback +Status: Open Bug Type: Output Control Operating System: OpenBSD PHP Version: 4.3.11 New Comment:
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'; ?> Previous Comments: ------------------------------------------------------------------------ [2005-05-22 15:34:39] [EMAIL PROTECTED] 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-21 02:10:51] 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'. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33088&edit=1