WXforum.net

Web Weather => Weather Website PHP/AJAX scripting => Topic started by: cirrus on January 02, 2017, 05:26:22 AM

Title: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: cirrus on January 02, 2017, 05:26:22 AM
Hello Ken!,
Just thought I'd give you a heads up that the Atom Warnings throws illegal string warnings on the array using PHP 7.1 ... reverted back to PHP 7.0 and all is well.

Example of PHP 7.1 errors when running nws-alerts.php:

Warning: A non-numeric value encountered in /home/rkcrk201/public_html/nws-alerts.php on line 127

Warning: Illegal string offset 'Central Col. R. Gorge, OR' in /home/rkcrk201/public_html/nws-alerts.php on line 219

Warning: Illegal string offset 'N. OR Cascades' in /home/rkcrk201/public_html/nws-alerts.php on line 219

Warning: Illegal string offset 'S. WA Cascades' in /home/rkcrk201/public_html/nws-alerts.php on line 219

Warning: Illegal string offset 'W. Col. R. Gorge, OR' in /home/rkcrk201/public_html/nws-alerts.php on line 219

Warning: Illegal string offset 'ORZ041' in /home/rkcrk201/public_html/nws-alerts.php on line 308

Fatal error: Uncaught Error: Cannot use string offset as an array in /home/rkcrk201/public_html/nws-alerts.php:308 Stack trace: #0 {main} thrown in /home/rkcrk201/public_html/nws-alerts.php on line 308

Best Regards,
-Kevin
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: yamiacaveman on January 02, 2017, 12:13:26 PM
www.pennlake.us

I'm using 7.1 and I don't seem to be having any issues.

yamiacaveman
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: cirrus on January 02, 2017, 04:21:09 PM
www.pennlake.us

I'm using 7.1 and I don't seem to be having any issues.

yamiacaveman

How many NWS alert zones are you using? I'm using 8 zones with cron to run nws-alerts.php
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: yamiacaveman on January 02, 2017, 08:45:10 PM
I am using 10 well 11 I have my town listed separately but I also have an alert for my county, which of-course my town is in, running a cron job on the server.
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: cirrus on January 02, 2017, 09:04:09 PM
Okay thanks...I don't know why the php 7.1 version on mine throws errors but my 7.0 version is fine... hopefully Ken can help
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: yamiacaveman on January 02, 2017, 09:30:49 PM
I wish I could help you out more but I haven't a clue. I am also running the Meteotemplate and that works fine also in 7.1
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: saratogaWX on January 03, 2017, 11:11:15 AM
Hello Ken!,
Just thought I'd give you a heads up that the Atom Warnings throws illegal string warnings on the array using PHP 7.1 ... reverted back to PHP 7.0 and all is well.

Example of PHP 7.1 errors when running nws-alerts.php:

Warning: A non-numeric value encountered in /home/rkcrk201/public_html/nws-alerts.php on line 127

Warning: Illegal string offset 'Central Col. R. Gorge, OR' in /home/rkcrk201/public_html/nws-alerts.php on line 219

Warning: Illegal string offset 'N. OR Cascades' in /home/rkcrk201/public_html/nws-alerts.php on line 219

Warning: Illegal string offset 'S. WA Cascades' in /home/rkcrk201/public_html/nws-alerts.php on line 219

Warning: Illegal string offset 'W. Col. R. Gorge, OR' in /home/rkcrk201/public_html/nws-alerts.php on line 219

Warning: Illegal string offset 'ORZ041' in /home/rkcrk201/public_html/nws-alerts.php on line 308

Fatal error: Uncaught Error: Cannot use string offset as an array in /home/rkcrk201/public_html/nws-alerts.php:308 Stack trace: #0 {main} thrown in /home/rkcrk201/public_html/nws-alerts.php on line 308

Best Regards,
-Kevin

that is very odd.  I'm still in Illinois so access to my debugging tools is limited.  I did download a copy of your nws-alerts.php and it appears to match with the current version (minus one comment line).

Looking at the errors reported, the line 127 error is in
Code: [Select]
  $cmyzc += substr_count($myv, '|'); // total count of codes in $myZC array
which is valid syntax for the substr_count() function.

The line 219 errors are in
Code: [Select]
    $noAlrt[$nk] = $nv[0];                                                                                    which should be alright if $noAlrt was previously declared to be an array().  On line 103, it is declared as a string by
Code: [Select]
$noAlrt  = '';
so should probably be
Code: [Select]
$noAlrt  = array(); to avoid that type conversion.  Similarly:


The line 308 errors are in
Code: [Select]
            $ad[$lCode][] = array($event,$urgency,$severity,$certainty,$effective,$expires,
                            $areaDesc,$instruction,$description,$clr,$ico,$sev,$cvk,$WA,$cvv[0],$poly,$ck);   
which (again) should be ok if $ad has been previously declared to be an array() .. unfortunately, that was declared
Code: [Select]
$ad      = ''; on line 101.  It should likely be
Code: [Select]
$ad      = array();
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: Curly on January 03, 2017, 11:31:44 AM
Try removing the periods and commas in the locations.
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: BCJKiwi on January 03, 2017, 03:35:13 PM
The likely issue is with the php 7.1 handling of arrays.

php 7.0 made some changes in array handling. php 7.1 has made further significant changes to array handling.

http://php.net/manual/en/migration71.incompatible.php
Of interest is;
The empty index operator is not supported for strings anymore
Applying the empty index operator to a string (e.g. $str[] = $x) throws a fatal error instead of converting silently to array.
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: Curly on January 03, 2017, 06:23:30 PM
I've made the two changes per Kens recommendations.

You can download the single file here:
http://www.weather.ricksturf.com/scripts/nws-alerts_138.zip
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: cirrus on January 03, 2017, 10:14:41 PM
I've made the two changes per Kens recommendations.

You can download the single file here:
http://www.weather.ricksturf.com/scripts/nws-alerts_138.zip

Hi Curly,
Tried it out on 7.1 but it produced errors;

Warning: A non-numeric value encountered in /home/rkcrk201/public_html/nws-alerts.php on line 128

Warning: Illegal string offset 'ORC065' in /home/rkcrk201/public_html/nws-alerts.php on line 327

Warning: Illegal string offset 'ORC065' in /home/rkcrk201/public_html/nws-alerts.php on line 327

Warning: Illegal string offset 'ORC065' in /home/rkcrk201/public_html/nws-alerts.php on line 327

Warning: Illegal string offset 'ORC065' in /home/rkcrk201/public_html/nws-alerts.php on line 327

Warning: Illegal string offset 'ORZ510' in /home/rkcrk201/public_html/nws-alerts.php on line 327

Warning: Illegal string offset 'WAZ521' in /home/rkcrk201/public_html/nws-alerts.php on line 327

Warning: Invalid argument supplied for foreach() in /home/rkcrk201/public_html/nws-alerts.php on line 371

Warning: array_keys() expects parameter 1 to be array, null given in /home/rkcrk201/public_html/nws-alerts.php on line 391

Warning: array_shift() expects parameter 1 to be array, null given in /home/rkcrk201/public_html/nws-alerts.php on line 392

Warning: Invalid argument supplied for foreach() in /home/rkcrk201/public_html/nws-alerts.php on line 473

Warning: Invalid argument supplied for foreach() in /home/rkcrk201/public_html/nws-alerts.php on line 518

Warning: Invalid argument supplied for foreach() in /home/rkcrk201/public_html/nws-alerts.php on line 599

Warning: A non-numeric value encountered in /home/rkcrk201/public_html/nws-alerts.php on line 1088

Works fine on 7.0 though

Regards,
-Kevin
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: Curly on January 04, 2017, 04:41:16 AM
Quote
Tried it out on 7.1 but it produced errors;

Have you tried it with the commas removed from the locations?
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: cirrus on January 04, 2017, 08:59:51 PM
Quote
Tried it out on 7.1 but it produced errors;

Have you tried it with the commas removed from the locations?

Curly,
I tried that with and without your nws-alerts.php mods and nws-alerts.php nor index.php would load at all.
Regards,
-Kevin
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: yamiacaveman on January 08, 2017, 03:27:08 PM
Ok  -- Now it's my turn  -- Had to switch back to PHP 7.0 for the alerts to work.

Is there a resolution to this problem? No problem if not, I'll just stay at 7.0 for now


Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: yamiacaveman on January 08, 2017, 03:30:28 PM
So -- This is what I get in the Alert box instead of the warning: Well let me say this the alert part works but when I go to the specific County I get the stuff below.

Fatal error: Uncaught Error: [] operator not supported for strings in /home/pennla7/public_html/nws-alerts-details-inc.php:137 Stack trace: #0 /home/pennla7/public_html/wxnws-details.php(52): include() #1 {main} thrown in /home/pennla7/public_html/nws-alerts-details-inc.php on line 137
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: Curly on January 08, 2017, 07:31:22 PM
As soon as I have access to ver 7.1, I'll get to work on a fix.
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: yamiacaveman on January 08, 2017, 08:07:31 PM
Hi Curly,
 
Like I said no hurry or problem for me, switching back to 7.0 is easy.

Just wanted to let someone know:  Funny, it worked up until today - I wonder what changed today??

Thanks
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: Curly on March 06, 2017, 08:07:39 PM
The errors are fixed for php ver 7.1.

Two non-configurable files were changed:
nws-alerts.php
nws-alerts-details-inc.php

http://www.weather.ricksturf.com/wxScripts.php
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: yamiacaveman on March 07, 2017, 08:16:09 AM
Thanks Curly,

I updated those two files and went up to 7.1

I won't have the ability to check on it today, but it seems to work now, and I will check on it when I can.

Thanks and thanks to ricksturf!
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: nagnal on July 30, 2017, 03:34:47 AM
Not working on PHP 7.1.1  any updates
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: saratogaWX on July 30, 2017, 10:02:50 AM
'Not working' is a bit vague to diagnose a problem.

What is the URL to the page(s) not working?
What are the PHP error messages shown?
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: nagnal on July 30, 2017, 02:45:04 PM
Sorry sir it was early when i posted this. I downloaded the above file and it took most of the errors away but these two
Warning: A non-numeric value encountered in C:\xampp\htdocs\weather\nws-alerts.php on line 128

Warning: A non-numeric value encountered in C:\xampp\htdocs\weather\nws-alerts.php on line 1088
my site is http://westsenecaweather.com
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: saratogaWX on July 30, 2017, 03:07:18 PM
Thanks!

Looking at check-fetch-times.php?show=versions on your site shows you have a few template scripts to update (just not nws-alerts.php ;) )

The Line 128 error is in the middle line of
Code: [Select]
foreach ($myZC as $myv) {
  $cmyzc += substr_count($myv, '|'); // total count of codes in $myZC array
}
and $myZC comes from
Code: [Select]
if(isset ($SITE['NWSalertsCodes'])) {$myZC = $SITE['NWSalertsCodes'];}
and your Settings.php has
Code: [Select]
$SITE['NWSalertsCodes'] = array(
"Cattaraugus|NYC009",
"Chautauqua|NYC013",
"Erie|NYC029",
);

The error message may be caused by nws-alerts.php
Code: [Select]
$cmyzc   = '';
which initializes the $cmyzc as a null string.  Try changing that to
Code: [Select]
$cmyzc   = 0;
which would cast it as an integer instead.  Maybe PHP 7.1 is more fussy about variable typing.

For the other error at line 1088 which is the second line in
Code: [Select]
$total_times = '';
$total_times += ($time_stopTotal - $time_startTotal);
try changing that to
Code: [Select]
$total_times = 0;
$total_times += ($time_stopTotal - $time_startTotal);
for the same reason.
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: nagnal on July 30, 2017, 03:29:42 PM
This one just poped up    Fatal error: Uncaught Error: [] operator not supported for strings in C:\xampp\htdocs\weather\nws-alerts.php:307 Stack trace: #0 C:\xampp\htdocs\weather\header.php(41): include_once() #1 C:\xampp\htdocs\weather\index.php(43): include('C:\\xampp\\htdocs...') #2 {main} thrown in C:\xampp\htdocs\weather\nws-alerts.php on line 307
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: saratogaWX on July 30, 2017, 04:41:11 PM
That's code
Code: [Select]
              (isset($abbrvd[1])) ? $abbrvDesc = $abbrvd[1] : $abbrvDesc = '';
              $logData[] = array($event,$cvk,$effective,$expires,$cis['icon'],$areaDesc,$abbrvDesc);
and it's caused by
Code: [Select]
$logData = '';
which should be
Code: [Select]
$logData = array();
Try that change...



Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: n7xrd on August 26, 2017, 10:27:57 AM
php version 7.1 gives this error when there is a Warning appears to run when no warnings are present??  Have made the changes in this thread to no avail.
Warning: Illegal string offset 'WAZ021' in /home/sfiala/public_html/nws-alerts.php on line 308

Fatal error: Uncaught Error: Cannot use string offset as an array in /home/sfiala/public_html/nws-alerts.php:308 Stack trace: #0 /home/sfiala/public_html/header.php(41): include_once() #1 /home/sfiala/public_html/index.php(43): include('/home/sfiala/pu...') #2 {main} thrown in /home/sfiala/public_html/nws-alerts.php on line 308
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: colonieweather on September 05, 2017, 07:48:27 PM
Hi,

I am getting that same error on same line now after going to php 7.1... "Fatal error: Uncaught Error: Cannot use string offset as an array"  and made Ken's recommended changes.  I saw that Curly updated script to fix, but link provided returns a 404.

-Chris
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: CNYWeather on September 06, 2017, 06:28:11 PM
I was able to get Version 2.01 off his downloads site
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: Curly on September 06, 2017, 06:36:54 PM
Version 2.01 is a beta.

Try version 1.39
http://www.weather.ricksturf.com/scripts/nws-alerts_139.zip

Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: colonieweather on September 06, 2017, 08:58:32 PM
Thanks Curly!

It seems to be bombing out on this line:
$logData[] = array($event,$cvk,$effective,$expires,$cis['icon'],$areaDesc,$abbrvDesc);

Got this error:  PHP Fatal error:  Uncaught Error: [] operator not supported for strings

Server is using v 7.1.4
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: Jasiu on September 06, 2017, 09:15:44 PM
I recommend adding a couple of lines of PHP temporarily to see what other (if any) issues you may have.

Code: [Select]
<?php
error_reporting 
(E_ALL E_STRICT);
ini_set("display_errors"1);
?>


I was able to clean up all the PHP 7 issues this way.
Title: Re: NWS (Atom) Alerts for Saratoga Templates PHP 7.1 problem
Post by: tmabell on September 24, 2017, 11:14:18 AM
EDIT: nws-alerts-log.php  does not work with php 7.1 due to the same issue.

Was this question ever answered directly? "PHP Fatal error:  Uncaught Error: [] operator not supported for strings"

I have this error in conjunction with another script and I'm not clear on how to resolve it.  This is a new issue since migrating to PHP 7.1.