php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39693 objects destroyed, but not always on callbacks functions
Submitted: 2006-11-30 14:57 UTC Modified: 2006-11-30 15:33 UTC
From: guessousmehdi at hotmail dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: 5.2.0 OS: windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: guessousmehdi at hotmail dot com
New email:
PHP Version: OS:

 

 [2006-11-30 14:57 UTC] 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-30 15:14 UTC] tony2001@php.net
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 15:33 UTC] guessousmehdi at hotmail dot com
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 24 22:01:33 2024 UTC