hsdn / metar-taf

This script is a PHP library which allows to parse the METAR and TAF code, and convert it to an array of data parameters.
Other
15 stars 4 forks source link

Issue with Conversions #8

Open trrisner opened 1 month ago

trrisner commented 1 month ago

with updated php(s), the string float or string int equations won't work. You have to convert all strings like wind speed or temperature to a float or an int to get the conversions to work. Otherwise it kicks out to a fatal error.

Change $windspeed = round(2.23694 $this->result['wind_speed']); // convert m/s to mi/h to $windspeed = round(2.23694 (float)$this->result['wind_speed']); // convert m/s to mi/h

AND

return round($conversion_factor $speed, 2); to return round((float)$conversion_factor (float)$speed, 2);

and all other occurrences in the script to get the code to work.

marek-knappe commented 4 weeks ago

@trrisner which php version it doesn't work and can you give me example metar raw that is not working for ?

trrisner commented 4 weeks ago

PHP v8.2.21 is the version. I couldn't get any raw metar to work with it. You got an error saying you can't multiply a string and int or string and float. In other code I've written, I've had to declare a variable as int or float to make it work. Same worked for this.

marek-knappe commented 4 weeks ago

@trrisner I tried to repliocate it in many different phps, just created simple script and I don't see it's an issue:

> cat test.php
<?php

$windspeed = round(2.23694 * (string)"3.80"); // convert m/s to mi/h
print $windspeed;

> php --version
PHP 8.3.8 (cli) (built: Jun  4 2024 14:53:17) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.8, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.8, Copyright (c), by Zend Technologies
> php test.php
9
trrisner commented 4 weeks ago

Interesting. Here is the error on my end:

Fatal error: Uncaught TypeError: Unsupported operand types: string * int in $YOURSCRIPT:1042 Stack trace:

0 $YOURSCRIPT(423): Metar->get_clouds()

1 $SCRIPT(146): Metar->parse()

2 {main}

thrown in $YOURSCRIPT on line 1042

If I simply change $observed['height'] = $this->convert_distance($found[5] 100, 'FT'); // convert feet to meters to $observed['height'] = $this->convert_distance((float)$found[5] 100, 'FT'); // convert feet to meters it works flawlessly.

Just wanted it in here in case someone else runs into the issue. Appreciate the work on this.

marek-knappe commented 3 weeks ago

For some reason i think the parser working bad and getting something more than just distance (maybe there is something else in the field, which mean to get that error i would need to get RAW METAR to see where is culprit instead of just mapping it to (float). Where from you are getting metar? is there a way that you can do var_dump($this->raw) in the first line of: public function parse()