issue.inc 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.

  switch ($_POST['op'] ? $_POST['op'] : arg(2)) {

changed to

  switch (!empty($_POST['op']) ? $_POST['op'] : arg(2)) {

2.

        '#default_value' => $status[$nid],

changed to

        '#default_value' => isset($status[$nid]) ? $status[$nid] : NULL,

3.

  $pid = $node->pid ? $node->pid : $_POST['edit']['pid'];

changed to

  $pid = !empty($node->pid) ? $node->pid : (isset($_POST['edit']['pid']) ? $_POST['edit']['pid'] : NULL);

4.

    if (trim($project->help)) {

changed to

    if (isset($project->help) && trim($project->help)) {

5.

    '#default_value' => ($query->states) ? $query->states : array(1, 2, 8, 13, 14),

changed to

    '#default_value' => !empty($query->states) ? $query->states : array(1, 2, 8, 13, 14),

Best wishes,

Mark.

CommentFileSizeAuthor
#2 project_issue_103795.patch5.66 KBdrewish
issue.inc_3.patch14.33 KBplumbley
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dww’s picture

Status: Needs review » Needs work

a) Doesn't apply cleanly anymore (my fault, sorry it took so long to get to this)

b) this:

+  if (isset($releases) && count($releases)) {

would be better as:

+  if (!empty($releases)) {

c) this:

+  $output .= isset($group) ? $group : NULL;

would be better as:

+  if (isset($group)) {
+     $output .= $group;
+  }

d) same here:

-  $output .= "$rss $link";
+  $output .= (isset($rss) ? $rss : '') . ' ' .(isset($link) ? $link : '');

your version is hard to understand, and doesn't follow our coding conventions regarding spaces and string concatenation.

otherwise, this is a good start, thanks! we'll certainly want something like this before we start porting to D6, so we might as well get this fixed up and committed to all branches.

also, even though i already committed the other patch that included a bunch of similar code, I'm having second thoughts about this style:

+      '#default_value' => isset($query->priorities) ? $query->priorities : NULL

I wonder if this would be better for both readability and speed (after the initial array definition):

  if (isset($query->priorities)) {
     $form['priorities']['#default_value'] = $query->priorities;
  }

I'm not sure which I prefer, but I wanted to raise it in case anyone else sees this issue and has strong opinions. ;)

drewish’s picture

Version: 4.7.x-1.0 » 5.x-2.x-dev
Status: Needs work » Needs review
FileSize
5.66 KB

tried to apply these by hand to HEAD and then worked on cleaning up some others.

hunmonk’s picture

Status: Needs review » Fixed

applied with some minor adjustments to 5.x-1.x. doesn't apply at all to either 4.7 branch -- i'll leave it as to be ported if anybody is interested,,,

Anonymous’s picture

Status: Fixed » Closed (fixed)