E_ALL Compliance: Fix notices in project.inc

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

project.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.

<?php
 
if ($_GET['edit'][$field]) {
?>

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

2.

<?php
 
'#default_value' => $node->title,
?>

change to
<?php
 
'#default_value' => isset($node->title) ? $node->title : NULL,
?>

3. Additional

<?php
  $output
= '';
?>

in project_project_view() which uses $output .= ... later.

4.

<?php
 
return $node;
?>

changed to
<?php
 
return isset($node) ? $node : NULL;
?>

since $node may not be set at point of return

Best wishes,

Mark.

AttachmentSize
project.inc_2.patch6.63 KB

#1

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

(Setting correct status)

#2

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

re-rolled for 5. made some small changes. in project_project_view() it seemed easier to just return once we had something and return null if we hadn't already returned.

i did a little testing on this and everything looked correct.

#3

drewish - July 13, 2007 - 16:13

here's that patch

AttachmentSize
project_103790.patch5.56 KB

#4

hunmonk - August 25, 2007 - 18:00
Status:patch (code needs review)» patch (to be ported)

applied to HEAD. patch doesn't apply cleanly to 4.7's

also, note that:

-  $form['project']['format'] = filter_form($node->format);
+  $form['project']['format'] = filter_form(isset($node->format) ? $node->format : NULL);

is wrong. i think FILTER_FORMAT_DEFAULT needs to be used instead of NULL.

#5

plumbley - September 1, 2007 - 12:09

@hunmonk - I agree it is probably not the intended use of $format, but I have deliberately not changed any behaviour here: the previous behaviour was that if $node->format was not explicitely set (which can happen in simple custom modules without a format field), the format will de-facto be set to NULL, with a PHP notice if enabled. Now we make it explicit, it is clear this is not the desired behaviour.

But since having stray NULL format seems a fairly common pattern for other modules, it may be safer to catch this specifically in e.g. filter_resolve_format() in filter.module (at least in 4.7), i.e. that filter specifically defaults a NULL format to FILTER_DEFAULT_FORMAT?

#6

hunmonk - September 1, 2007 - 13:38

you'd need to file an issue against core to address the problem in the way you describe.

#7

drewish - September 20, 2007 - 14:56
Version:5.x-1.x-dev» 4.7.x-2.x-dev

looks like hunmonk committed this to HEAD

#8

aclight - April 12, 2008 - 23:54
Status:patch (to be ported)» fixed

We're not supporting the 4.7 branch anymore, so I'm closing this.

#9

Anonymous (not verified) - April 27, 2008 - 00:02
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.