Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Conversions #8

Open
trrisner opened this issue Aug 13, 2024 · 5 comments
Open

Issue with Conversions #8

trrisner opened this issue Aug 13, 2024 · 5 comments

Comments

@trrisner
Copy link

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
Copy link

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

@trrisner
Copy link
Author

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
Copy link

@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
Copy link
Author

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
Copy link

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants