Project:Drupal For Firebug
Version:6.x-1.3
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

There's a subtle bug in your code (d5 and d6 versions):

/**
* Implementation of hook_exit()
*/
function drupalforfirebug_exit() {
  // Garbage Collection
  global $dfp_runtime;
  unset($dfp_runtime);
}

should be changed to:

/**
* Implementation of hook_exit()
*/
function drupalforfirebug_exit() {
  // Garbage Collection
  global $dfp_runtime;
  unset($_GLOBALS['dfp_runtime']);
}

Your code only unsets the local variable $dfp_runtime, so in your case it achieves nothing.
See the PHP documentation for the unset() function which says::

"The behavior of unset() inside of a function can vary depending on what type of variable you are attempting to destroy.
If a globalized variable is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called."

(Passing $dfp_runtime by reference does not work either).

However I think the unset() in this code is OK, since you are removing an array element:

/**
* Output Function to Return the Results of the Log
*/
function drupalforfirebug_get($panetype) {
  global $dfp_runtime;
  $output = '';
  if (isset($dfp_runtime['firebug_messages'][$panetype])) {
    foreach($dfp_runtime['firebug_messages'][$panetype] as $message) {
      $output .= '<div>'. $message .'</div>';
    }
    unset($dfp_runtime['firebug_messages'][$panetype]);
    return $output;
  }
}

Marc

Comments

#1

Category:bug report» support request

Correction, should be changed to:

/**
* Implementation of hook_exit()
*/
function drupalforfirebug_exit() {
  // Garbage Collection
  unset($_GLOBALS['dfp_runtime']);
}

Marc

#2

Status:active» fixed

Thanks! Just committed to CVS.

#3

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

#4

Version:6.x-1.x-dev» 6.x-1.3
Category:support request» bug report
Status:closed (fixed)» needs work

I'm surprised no one caught this. The actual $GLOBALS variable does not start with an underscore. Should be changed to:

/**
* Implementation of hook_exit()
*/
function drupalforfirebug_exit() {
  // Garbage Collection
  unset($GLOBALS['dfp_runtime']);
}

#5

mark.carver, you are absolutely right. I'm also surprised that this bug wasn't caught. Reference: http://php.net/manual/en/reserved.variables.globals.php

#6

Status:needs work» reviewed & tested by the community

Can this be committed and set to fixed?

#7

Status:reviewed & tested by the community» fixed

This has been fixed in the -dev version which will become a stable release soon.

#8

Thank you, I've been waiting for this to leave my queue.

#9

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.