php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11091 globa and isset in function difficult to use
Submitted: 2001-05-24 12:33 UTC Modified: 2001-06-18 10:11 UTC
From: gary dot wong at spingroup dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.5 OS: NT4SP6
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: gary dot wong at spingroup dot com
New email:
PHP Version: OS:

 

 [2001-05-24 12:33 UTC] gary dot wong at spingroup dot com
PHP 4.04 to 4.05 upgrade introduced new problems in PHPLIB.  In page.inc, there is a function like this:

function page_close() {
  global $sess, $user;
  if (isset($sess)) {
    $sess->freeze();
  }
  if (isset($user)) {
      $user->freeze();
  }
}

The intent is that if the $user or $sess classes were never set, then it would not try to call the freze method.  However, in 4.05, the "global" statement cause the "isset" statement to return "true" just by declaring them global.  I read from the other bug reports that this is kind of a "feature" where the global simply creates a "reference" to the $GLOBALS.  But then, how do we recode?  The only solution I found is this:

function page_close() {
  if (in_array("sess",array_keys($GLOBALS)))
    global $sess;
  if (in_array("user",array_keys($GLOBALS)))
    global $user;

  if (isset($sess)) {
    $sess->freeze();
  }
  if (isset($user)) {
    $user->freeze();
  }
}

This is kind of messy!  Is there any other way? Or can "global" be changed so that it only creates the reference if the var exists?

Thanks,
Gary

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-18 10:11 UTC] kalowsky@php.net
$GLOBALS['sess'] will work as well.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 09:01:31 2024 UTC