E_ALL Compliance: Fix PHP Notices in project.module

plumbley - December 17, 2006 - 13:29
Project:Project
Version:5.x-1.x-dev
Component:Projects
Category:bug report
Priority:minor
Assigned:Unassigned
Status:closed
Description

project.module produces various PHP Notices with E_ALL on. These are all due to variables, array keys or object fields which may not exist when used.

This patch fixes those that I spotted, by changing to equivalent behaviour without Notices.

Examples:
1. Additional

<?php
  $output
= '';
?>

in project_page_overview(), that uses $output .= ... later.

2.

<?php
 
if ($_POST['edit']['rid']) {
?>

changed to
<?php
 
if (!empty($_POST['edit']['rid'])) {
?>

3.

<?php
   
if ($project->release_count > 1) {
?>

changed to
<?php
   
if (isset($project->release_count) && $project->release_count > 1) {
?>

4.

<?php
   
if (module_invoke($module, 'project_sort_methods', 'group by date', $sort_method) && $date = _project_date($project->changed)) {
?>

changed to
<?php
+    if (isset($module) && module_invoke($module, 'project_sort_methods', 'group by date', $sort_method)
         &&
$date = _project_date($project->changed)) {
?>

(Actually this indicates some other possible problem project_page_overview(), since presumably $module ought to exist at this point. So maybe this should be left as a bug to be fixed).

5.

<?php
  $output
.= '<div class="project" id="project-overview">' . $projects . '</div>';
?>

changed to
<?php
  $output
.= '<div class="project" id="project-overview">' . (isset($projects) ? $projects : '') . '</div>';
?>

although an alternative would be to show an alternative message if no projects were listed.

Best wishes,

Mark.

AttachmentSize
project.module_5.patch4.38 KB

#1

plumbley - December 17, 2006 - 13:54
Status:active» patch (code needs review)

(Setting correct status)

#2

drewish - July 13, 2007 - 16:19
Version:4.7.x-1.0» 5.x-1.x-dev

here's a re-roll for 5

AttachmentSize
project.module_103791.patch3.24 KB

#3

hunmonk - August 25, 2007 - 17:37
Status:patch (code needs review)» patch (code needs work)

this is definitely wrong:

@@ -708,7 +709,7 @@
         'href' => "project/issues/$project->nid",
       );
     }
-    if (module_invoke($module, 'project_sort_methods', 'group by date', $sort_method) && $date = _project_date($project->changed)) {
+    if (isset($module) && module_invoke($module, 'project_sort_methods', 'group by date', $sort_method) && $date = _project_date($project->changed)) {
       $projects .= "<h3>$date</h3>";
     }
     $project->class = ($class == 'even') ? 'odd': 'even';

what are you doing that's resulting in $module not being set? that doesn't look possible to me. if it is, then we need to fix elsewhere.

#4

plumbley - September 1, 2007 - 12:21

@hummonk - Sorry this is so long ago now that I don't remember what I did exactly. But I only ever started to try out Project, so this was probably either (1) browse of projects with no projects created yet, or (2) creation of first project. I think (2) is most likely, since most node add/edit forms ask for something about the (assumed to exist) item, but on create it doesn't exist yet so instead returns NULL node with PHP Notice.

A clean bare installation would be the most likely place to see this I think, since creating the first of a particular type can sometimes be a boundary case that isn't always catered for well.

#5

hunmonk - September 1, 2007 - 13:40

the above mentioned weirdness w/ $module has been fixed elsewhere, so rip that out and roll a new patch against the latest code.

#6

hunmonk - September 19, 2007 - 20:58
Status:patch (code needs work)» patch (code needs review)

this should do what we need. quick review would be nice.

AttachmentSize
e_all1.patch2.72 KB

#7

dww - September 19, 2007 - 23:48
Status:patch (code needs review)» patch (reviewed & tested by the community)

Visually looks fine and light testing on a local site reveals no problems. Didn't actually turn on E_ALL yet, so it's possible there are other warnings lurking, but this is certainly an improvement. Thanks.

#8

drewish - September 20, 2007 - 15:30
Status:patch (reviewed & tested by the community)» patch (code needs review)

i turned on E_ALL and found a few more. we might as well get them all at once.

AttachmentSize
project_103791.patch3.71 KB

#9

hunmonk - September 21, 2007 - 10:52

-    $version_form = drupal_get_form('project_release_version_filter_form', $version);
+    $version_form = drupal_get_form('project_release_version_filter_form');

something's wrong here. that form isn't built anywhere else that i can see, so what's the deal with function project_release_version_filter_form($version = NULL) if we're removing $version in the patch? do we need to get rid of $version as an arg, or correctly supply $version in function project_page_overview()?

#10

hunmonk - September 21, 2007 - 10:53
Status:patch (code needs review)» patch (code needs work)

#11

hunmonk - September 28, 2007 - 15:00
Version:5.x-1.x-dev» 4.7.x-2.x-dev
Status:patch (code needs work)» patch (to be ported)

reviewed, tested, committed to 5.x-1.x -- leaving to be ported if anybody cares to fix this in the older versions.

#12

dww - October 6, 2007 - 17:22
Version:4.7.x-2.x-dev» 5.x-1.x-dev
Status:patch (to be ported)» fixed

#13

Anonymous - October 20, 2007 - 17:31
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.