There is a special case when the visibility is very low, something under 1 mile, for example:
$metar_raw_string = 'KBLI 211420Z AUTO 00000KT 1/4SM R16/1800V3500FT FZFG VV001 M03/M04 A3022 RMK AO2';

In this case... we'll get a notice in logs because $metar->visibility_miles will not be initialized.

Everything that is past 1 mile, for example:

$metar_raw_string = 'KBLI 211420Z AUTO 00000KT 1 1/4SM R16/1800V3500FT FZFG VV001 M03/M04 A3022 RMK AO2'; will work.

I think that we can add a quick fix after line 599 in weather_parser.inc file:
instead of:

if ($matches[3] == '/') {
      // This is a fractional visibility, we need to convert this
      $visibility = $metar->visibility_miles + $matches[2] / $matches[4];
    }

we should check if $metar->visibility_miles is set or not, something like:

if ($matches[3] == '/') {
      if (!isset($metar->visibility_miles)) {
        $metar->visibility_miles = 0;
      }
      // This is a fractional visibility, we need to convert this
      $visibility = $metar->visibility_miles + $matches[2] / $matches[4];
    }
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

toddy’s picture

Assigned: Unassigned » toddy
Status: Active » Reviewed & tested by the community

Very good catch, thanks a lot for reporting this. I'll fix this and release a new version shortly.

Regards,
Toddy

Status: Reviewed & tested by the community » Needs work

The last submitted patch, weather.module-visibility_miles-notices.patch, failed testing.

toddy’s picture

Status: Needs work » Fixed

Applied a fix for this.

Status: Fixed » Closed (fixed)

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

IKE0088’s picture

I am receiving the same error message:
Notice: Undefined property: stdClass::$visibility_miles in _weather_parse_visibility() (line 601

Did the fix noted above work? From the notes, it looks like it failed testing. Please advise.

toddy’s picture

I've just released version 7.x-1.5 which includes a fix for this.

Regards,
Tobias