php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40604 Objects disappear from the global scope
Submitted: 2007-02-23 08:49 UTC Modified: 2007-02-23 23:59 UTC
From: dagdamor at simps dot ru Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.1 OS: Windows
Private report: No CVE-ID: None
 [2007-02-23 08:49 UTC] dagdamor at simps dot ru
Description:
------------
Objects seem to disappear from the global scope when you try to access them from the output buffer callback function. Regular variables (i.e. not objects) don't disappear and work alright.

After some additional research I've noticed that if your PHP program has many objects in the global scope, some of them don't disappear, while others do. Looks very strange...

I hope this is not documentation misinterpretation, because I used global variables, objects including in OB callbacks in PHP4, and it worked fine. In other words, I hope this is not "You can't use global variables there" case.

Reproduce code:
---------------
<?php

function handler($content)
{
  global $obj;
  return isset($obj)?"OK":"Error";
}

class MyClass {}
$obj=new MyClass();

ob_start("handler");

?>

Expected result:
----------------
OK

Actual result:
--------------
Error

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-23 09:04 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

the object gets destroyed before you get output - well actually you don\'t produce output
 [2007-02-23 23:26 UTC] dagdamor at simps dot ru
I didn't understand your reply at all :( could you please provide a bit more explanatory response?

I see that the object gets destroyed before the script ends its work (since it's inaccessible in the provided example), but I don't understand why it's expected behavior... I never destroyed that object manually, and created it expecting it to work till the very end of script.
 [2007-02-23 23:33 UTC] tony2001@php.net
All objects are destroyed _before_ output callbacks are called.
 [2007-02-23 23:46 UTC] dagdamor at simps dot ru
Okay... I understand.

But since it's not obvious and is a BC break, maybe it makes sense to write about the issue in the documentation? (For example, in the Output Control section.) I don't want anyone else to stand on the same rake.
 [2007-02-23 23:59 UTC] tony2001@php.net
>But since it's not obvious and is a BC break

BC break? This behaviour exists at least since 5.1.0.
And this can't be a BC break comparing to PHP4, for classes in PHP4 do not have any destructors.

>maybe it makes sense to write about the issue in the documentation? 

Probably. 
I'm sure the documentation team would appreciate any help.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 05 22:01:31 2024 UTC