very trivial - PHP STRICT notice when first installing and misc other places

dman - February 7, 2009 - 13:20
Project:Taxonomy Image
Version:6.x-1.x-dev
Component:Code
Category:task
Priority:minor
Assigned:Unassigned
Status:closed
Description

STRICT is boring, but best to clear them up I guess...

notice: Undefined index: file in /var/www/drupal6/sites/all/modules/contributions/taxonomy_image/contributed/taxonomy_image_node_display/taxonomy_image_node_display.module on line 24.

This occurred on most pages after I first enabled the module (but had not yet configured it). Others turned up elsewhere. I think they go away after a while - caching or default configs subdue the warnings.

My fixes are trivial isset() or empty() in a couple of places:

Index: taxonomy_image/taxonomy_image.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/taxonomy_image/taxonomy_image.module,v
retrieving revision 1.12.4.13.2.29
diff -u -u -p -r1.12.4.13.2.29 taxonomy_image.module
--- taxonomy_image/taxonomy_image.module 1 Feb 2009 19:23:10 -0000 1.12.4.13.2.29
+++ taxonomy_image/taxonomy_image.module 7 Feb 2009 13:13:04 -0000
@@ -243,7 +243,7 @@ function taxonomy_image_get_object($tid,
     $image[$tid]->url = file_create_url($image[$tid]->path);
   }
   // Get more properties if we had an image.
-  if ($image[$tid]->path) {
+  if (!empty($image[$tid]->path)) {
     $image[$tid]->tid = $tid;
     $img = getimagesize($image[$tid]->path);
     // Make sure it worked.
@@ -259,7 +259,7 @@ function taxonomy_image_get_object($tid,
     $image[$tid]->type_extension = $exts[$img[2]];
     $image[$tid]->tags = $img[3];
     $image[$tid]->bits = $img['bits'];
-    $image[$tid]->channels = $img['channels'];
+    $image[$tid]->channels = isset($img['channels']) ? $img['channels'] : '';
     $image[$tid]->mime = $img['mime'];
     $image[$tid]->term = drupal_get_path_alias(taxonomy_term_path(taxonomy_get_term($tid)));
     $image[$tid]->img = '<img src="'. $image[$tid]->url
Index: taxonomy_image/contributed/taxonomy_image_node_display/taxonomy_image_node_display.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/taxonomy_image/contributed/taxonomy_image_node_display/Attic/taxonomy_image_node_display.module,v
retrieving revision 1.1.4.10
diff -u -u -p -r1.1.4.10 taxonomy_image_node_display.module
--- taxonomy_image/contributed/taxonomy_image_node_display/taxonomy_image_node_display.module 1 Feb 2009 21:03:17 -0000 1.1.4.10
+++ taxonomy_image/contributed/taxonomy_image_node_display/taxonomy_image_node_display.module 7 Feb 2009 13:13:04 -0000
@@ -21,7 +21,7 @@ function taxonomy_image_node_display_nod

     $preset = variable_get('taxonomy_image_node_preset', 'ORIGINAL');
     $valid_nodes = variable_get('taxonomy_image_node_view', array());
-    if ($valid_nodes[$node->type] && isset($node->taxonomy)) {
+    if (!empty($valid_nodes[$node->type]) && isset($node->taxonomy)) {
       $images = array();
       $view_link = variable_get('taxonomy_image_node_view_link', TRUE);
       foreach ($node->taxonomy as $tid => $term) {

AttachmentSize
taxonomy_image-strict_notice-20090208.patch2.38 KB

#1

NancyDru - February 12, 2009 - 17:37

Thanks. I would prefer to not have strict flags, even though D7 cannot handle strict mode (yet).

Would an "isset" be better on $image[$tid]->path?

If you don't have "$img['channels']" I would guess you are not on PHP5. I would really prefer to stop supporting PHP4.

On $valid_nodes, I think I would prefer an "isset" after an array_filter.

#2

NancyDru - February 12, 2009 - 17:49
Status:needs review» fixed

Committed to both branches. Thanks.

#3

dman - February 12, 2009 - 22:46

Coming at it from this end, I'm sometimes not sure when I should use isset() vs empty() - or if there's any difference at all. That requires really digging into the code, when all I really need to do is mute a trivial message.
Heck, sometimes I just stick @ at the beginning of the line. That works fine too.
So whichever makes you more comfortable.
I had no $img['channels'] in php5. It may have been on a Mac OSX though..

.dan.

#4

NancyDru - February 12, 2009 - 23:09

Something can be empty but set. But the way the Forms API works, throwing an "array_filter" at it unsets the non-selected types.

I still did the "isset" on those three PHP5 pieces from "getimagsize."

I also set "error_reporting" to 32767 on my two development sites, so hopefully I'll be seeing these things again (had to turn it off for D7).

#5

NancyDru - February 15, 2009 - 20:04
Status:fixed» closed

Clearing the issue queue.

 
 

Drupal is a registered trademark of Dries Buytaert.