ID:               39693
 User updated by:  guessousmehdi at hotmail dot com
 Reported By:      guessousmehdi at hotmail dot com
 Status:           Bogus
 Bug Type:         Output Control
 Operating System: windows
 PHP Version:      5.2.0
 New Comment:

hi,
that looks very weird for me,
and obviously I don't have all the knowledge relative to the 
way php destruct objects. However, I notice that this behavior was not
there on previous release of php (and even recent release of php5). So
at least, would you be kind , and tell me what's would be a satisfying
solution to still be able to call object on my callback function
despite the termination ? Does creating a new reference to the object
$t1, in a "dummy" variable by doing $t2=$t1 a good solution , or is
there something wiser ?

thanks


Previous Comments:
------------------------------------------------------------------------

[2006-11-30 15:14:33] [EMAIL PROTECTED]

This is expected behaviour.
Object destructors are called before flushing the output buffers, so if
your object has refcount == 1 (which is the case with $t2=$t1 commented
out), $t1 is already destroyed when the callback is called.
You do not see the error message, because the error happens in the
function which flushes the buffer, so this is also expected.

------------------------------------------------------------------------

[2006-11-30 14:57:56] guessousmehdi at hotmail dot com

Description:
------------
When I  terminate a script by an exit,
before end  of execution, ob_start allows to 
to invoke a callback function.
>From this callback function, I cannot access to an 
object (in source example:$t1) previously initiated in the script. 
However, if I save a dummy copy of that object in a new variable (for
instance $t2), then it work as expected.
In the source example, just uncomment the line "$t2=$t1;"
to see what I mean.
I works normally in previous version of php (php 4 and first releases
of 5)
I cannot remplace the exit at the end by an ob_flush(), because I'm
including a big script in my real work, which is much more complex than
the example I provide.

Reproduce code:
---------------
<?php
class test{
        function nice_string(){
                 return "hello world, how are you ?";
        }       
}
$t1 =  new test();

// the following commented line makes a difference 
//$t2=$t1;

function callbackfunc($output){
         global $t1;                    
   $output ="chocolate<br>". $output . "<br>". $t1->nice_string();    

        return "$output";
}
ob_start('callbackfunc');
echo "what a nice day";
exit();  ?>

Expected result:
----------------
should output:
chocolate
what a nice day
hello world, how are you ?

Actual result:
--------------
output nothing,
blank page,
probably a fatal error without any indication about it.

Uncommenting line $t2=$t1 and it works fine again.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=39693&edit=1

Reply via email to