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.
| Attachment | Size |
|---|---|
| project.inc_2.patch | 6.63 KB |

#1
(Setting correct status)
#2
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
here's that patch
#4
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
@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
you'd need to file an issue against core to address the problem in the way you describe.
#7
looks like hunmonk committed this to HEAD
#8
We're not supporting the 4.7 branch anymore, so I'm closing this.
#9
Automatically closed -- issue fixed for two weeks with no activity.