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
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
I think it is ironic that I am filing a patch for undefined variables for the coder tough love review module. :)