Comments

brmassa’s picture

Status: Active » Needs review

Guys,

Using the latest D6, which reports PHP E_ALL warnings, the Coder module, when scanning files, rise dozen warnings like the title: Undefined offset: -1 in */modules/coder/coder.module on line 1203.

consider implement such patch (starting from line 1202 more or less):

          if ($in_quote) {
            if (empty($this_quote_lines[$this_quote_index])) {
              $this_quote_lines[$this_quote_index] = '';
            }
            $this_quote_lines[$this_quote_index] .= $char;
            if ($in_quote == '"') {
              if (empty($this_doublequote_lines[$this_doublequote_index])) {
                $this_doublequote_lines[$this_doublequote_index] = '';
              }
              $this_doublequote_lines[$this_doublequote_index] .= $char;
            }

regards,

massa

scor’s picture

I notice the same thing in 2.x (not in 1.x). The strange thing is that it doesn't happen all the time. It seems to only happen the first time you run coder against a module. can't really understand why though...

dave reid’s picture

Yeah I just updated to the 6.x-2.x and this notice is really annoying...

stella’s picture

I can't reproduce this issue with 6.x-2.x. Can you confirm you ran update.php after upgrading the module?

scor’s picture

I experienced this when using coder 2.x on a fresh Drupal core. I believe this might have to do with the caching.

Steps to reproduce:
- cvs co -r DRUPAL-6--2 -d coder contributions/modules/coder
- enable coder in admin/build/modules
- click on the 'code review' link of the aggregator module for example: you will see all these warnings appearing
- reload the page and they disappear

The same behavior happens for any module.

stella’s picture

Status: Needs review » Active

I can reproduce this consistently when running coder's simpleTests. However I'm not sure that the patch suggested in #1 is the correct solution.

dave reid’s picture

I can also pretty much reproduce this bug when selecting all the coder tests except for the converting x to x tests, selecting all minor results, and running the check on one module.

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new968 bytes

I adjusted the 'reset' values of $this_quote_index and $this_doublequote_index to 0 instead of -1. The default value for the array being used with these indexes is array(''), and after studying the code, it doesn't seem to make sense to use -1. If we want to change the first value of the array, it should be 0. After I patched coder.module, I tested this with making the first quote or double-quote lines in a module with an error that should be caught, and they were correctly caught, so there is no difference in results.

I hope I made that clear? I doubt it. Either way, this patch works for me and I get no change in results, and now no PHP notice errors.

eMPee584’s picture

StatusFileSize
new3.37 KB

that patch seems good... i found another problem: coder tries to operate on theme info files, which is stupid and causes alot of errors. Here's the patch, including the former one. *No-more-php-errors-frenzy* !!! ;)

eMPee584’s picture

StatusFileSize
new622 bytes

and here is another undefined index error fix..

dave reid’s picture

Title: Undefined offset: -1 in /var/www/drupal-hfopi/sites/all/modules/coder/coder.module on line 1203. » PHP notice errors: undefined indexes and offsets
StatusFileSize
new1.62 KB

Combined patches in #8 and #10. For the sake of the kittens, let's make #9 a separate issue so that this patch can get committed. It'd be nice not to have to scroll through tons of undefined index errors to get to the code results.

deekayen’s picture

Priority: Critical » Normal
StatusFileSize
new1.61 KB

I have similar problems. The attached patch is how I made the notices go away. I used #1's style (modified) to fix the 1203 and 1205 quote notices and #11 to fix the $link notice. I don't know the implications of #11's default index change, and I'm sure about what isset() does, which is why I'm offering up another solution.

stella’s picture

Status: Needs review » Fixed

Fixed. None of the patches above corrected the real issue for the negative index - there was a reason the index variables were initialized to -1. However, this is now fixed and will be available in the next dev release later today.

Cheers,
Stella

dave reid’s picture

Thanks you for finally fixing this! :) Being a developer and using E_ALL | E_NOTICE really gets annoying sometimes, so this is one thing off the list!

stella’s picture

@Dave Reid: no problem. Though 6.x-1.x is still the recommended version ;) If you're at Drupalcon, please come to the 'coder' sprint tomorrow where we'll be working on 6x to 7x reviews and other improvements.

Cheers,
Stella

dave reid’s picture

I'm debating it. I think I sat right behind you at the usability session yesterday with webchick, but I didn't introduce myself. Silly me.

Status: Fixed » Closed (fixed)

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