PHP notes and undefined variables oh my!

Dave Reid - November 29, 2008 - 21:22
Project:Coder Tough Love
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Issue tags:ironic
Description

When running the Coder Tough Love review, I get the following notices:
# notice: Undefined variable: potentially_inside_a_hook_menu in /home/davereid/Projects/drupal6/sites/all/modules/contrib/coder_tough_love/coder_tough_love.module on line 171.
# notice: Undefined variable: potentially_inside_a_hook_menu in /home/davereid/Projects/drupal6/sites/all/modules/contrib/coder_tough_love/coder_tough_love.module on line 176.
# notice: Undefined variable: potentially_inside_a_hook_menu in /home/davereid/Projects/drupal6/sites/all/modules/contrib/coder_tough_love/coder_tough_love.module on line 183.

<?php
function _coder_tough_love_admin_menu_descriptions(&$coder_args, $review, $rule, $lines, &$results) {
  foreach (
$lines as $line_number => $line) {
   
$line = implode(' ', $line); // concat'd parts.
...
   
// if we're inside, look at the line and check for an admin path.
   
if ($potentially_inside_a_hook_menu && preg_match('/\[[\'"]admin\//', $line)) {
     
$potentially_found_an_admin_path = $line_number; // used in the error.
   
}
?>

Should be changed to:

<?php
function _coder_tough_love_admin_menu_descriptions(&$coder_args, $review, $rule, $lines, &$results) {
  foreach (
$lines as $line_number => $line) {
   
$line = implode(' ', $line); // concat'd parts.
   
$potentially_inside_a_hook_menu = 0;
...
   
// if we're inside, look at the line and check for an admin path.
   
if ($potentially_inside_a_hook_menu && preg_match('/\[[\'"]admin\//', $line)) {
     
$potentially_found_an_admin_path = $line_number; // used in the error.
   
}
?>

#1

Dave Reid - November 29, 2008 - 21:25
Title:notice: Undefined variable: potentially_inside_a_hook_menu» notice: Undefined variable

Now I'm also getting:
* notice: Undefined variable: potentially_found_an_admin_path in /home/davereid/Projects/drupal6/sites/all/modules/contrib/coder_tough_love/coder_tough_love.module on line 177.
* notice: Undefined variable: potentially_found_an_admin_path in /home/davereid/Projects/drupal6/sites/all/modules/contrib/coder_tough_love/coder_tough_love.module on line 184.

$potentially_found_an_admin_path = 0; should also be added along with $potentially_inside_a_hook_menu = 0;.

#2

Dave Reid - March 21, 2009 - 19:06
Title:notice: Undefined variable» PHP notes and undefined variables oh my!
Status:active» needs review

I think it is ironic that I am filing a patch for undefined variables for the coder tough love review module. :)

AttachmentSize
340tl-tsk-tsk-undefined-variables-D6.patch 1.94 KB
 
 

Drupal is a registered trademark of Dries Buytaert.