Page 3 of 4

Re: Saratoga Templates with PHP 7

Posted: Sun 18 Feb 2018 9:57 pm
by ConligWX
saratogaWX wrote:All my sites are now running 7.2.2. I did have to upgrade my JPGraph software from 4.0.1 to 4.2.0 to avoid some errata in error_log. Everything else is ok.
Yep just noticed my error.log and seen there was a newer version for 7.2

had another issue though more likely WU again...

WU-Forceast.php error, file was incomplete (23kb). now set the file to 23000bytes or less it will be removed and downloaded again.

Re: Saratoga Templates with PHP 7

Posted: Thu 22 Feb 2018 8:29 pm
by Mapantz
I have just upgraded to 7.2.2 as well. I've fixed everything I could find. But, it's just the wuforecast and wuhistory. I only get a notice about 'foreach' on the wuforecast.
The wuhistory has a massive log of errors running in to megabytes.

It just seems to be two things, though.

Code: Select all

[22-Feb-2018 19:22:14 Europe/London] PHP Warning:  Use of undefined constant weekday - assumed 'weekday' (this will throw an Error in a future version of PHP) in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 1990

Code: Select all

[22-Feb-2018 01:01:06 Europe/London] PHP Notice:  A non well formed numeric value encountered in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 2760

Re: Saratoga Templates with PHP 7

Posted: Thu 22 Feb 2018 9:50 pm
by saratogaWX
Are you using WU-History-inc.php - Version 3.4b - 01-Dec-2017 ? If not, download from here

I'm not seeing those errors in my error_log with 7.2.2

Re: Saratoga Templates with PHP 7

Posted: Thu 22 Feb 2018 10:51 pm
by Mapantz
Hi Ken

Yes. I updated to that version a few weeks ago.
I cleared the error log and tried the page and I instantly get the errors

Code: Select all

[22-Feb-2018 22:49:30 Europe/London] PHP Notice:  A non well formed numeric value encountered in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 2760
[22-Feb-2018 22:49:30 Europe/London] PHP Warning:  Use of undefined constant weekday - assumed 'weekday' (this will throw an Error in a future version of PHP) in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 1990
Everything on the script works, though.

Are they any specific modules in php 7.2 that need to be checked or unchecked? I left them all default.

Re: Saratoga Templates with PHP 7

Posted: Thu 22 Feb 2018 11:03 pm
by saratogaWX
For the second error, change

Code: Select all

					$data = '<td class = "date">' . substr($tdate[weekday], 0, 3) . '</td><td class = "date"><a href="' . $PHP_SELF . '?ID=' . $WUID . '&month=' . $pmo . '&day=' .$pda . '&year=' . $pyr . '&mode=1&units=' . $units . '">' . $pda . '</a></td>';  //Date/Time
to

Code: Select all

					$data = '<td class = "date">' . substr($tdate['weekday'], 0, 3) . '</td><td class = "date"><a href="' . $PHP_SELF . '?ID=' . $WUID . '&month=' . $pmo . '&day=' .$pda . '&year=' . $pyr . '&mode=1&units=' . $units . '">' . $pda . '</a></td>';  //Date/Time
For the first error.. I don't have a line 2760 in the script. Mine stops at 1564 in WU-History-inc.php so I don't know which line in the script it is complaining about.

I do note that your second error says line 1990 but is really line 996 in WU-History-inc.php Using the same 994 offset would have me looking at (2760-994)=1766 and that is beyond the 1564 in the WU-History-inc.php. So it may be something in your WU-History.php (but mine is only 42 lines long).

Please zip and post both your WU-History-inc.php and WU-History.php pages, and I'll take a look.

Re: Saratoga Templates with PHP 7

Posted: Thu 22 Feb 2018 11:06 pm
by ConligWX
Mapantz wrote:I have just upgraded to 7.2.2 as well. I've fixed everything I could find. But, it's just the wuforecast and wuhistory. I only get a notice about 'foreach' on the wuforecast.
The wuhistory has a massive log of errors running in to megabytes.

It just seems to be two things, though.

Code: Select all

[22-Feb-2018 19:22:14 Europe/London] PHP Warning:  Use of undefined constant weekday - assumed 'weekday' (this will throw an Error in a future version of PHP) in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 1990

Code: Select all

[22-Feb-2018 01:01:06 Europe/London] PHP Notice:  A non well formed numeric value encountered in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 2760
I've check my error logs too and cannot find any issues with WU-History.php at all.
saratogaWX wrote: For the first error.. I don't have a line 2760 in the script. Mine stops at 1564 in WU-History-inc.php so I don't know which line in the script it is complaining about.

Same here, mine is much shorter than Mapantz's file.

Re: Saratoga Templates with PHP 7

Posted: Thu 22 Feb 2018 11:21 pm
by Mapantz
That's because there's a space between each line of text/code. It always does that after uploading the file.

Here's the correct lines:

Code: Select all

[22-Feb-2018 23:20:49 Europe/London] PHP Notice:  A non well formed numeric value encountered in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 1381
[22-Feb-2018 23:20:49 Europe/London] PHP Warning:  Use of undefined constant weekday - assumed 'weekday' (this will throw an Error in a future version of PHP) in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 996
Second line fixed, Ken. :)

Code: Select all

	$newdate = mktime (0,0,0,$month,$nday,$year);

Re: Saratoga Templates with PHP 7

Posted: Thu 22 Feb 2018 11:34 pm
by saratogaWX
Ahh.. that explains the line count issue...

Line 1381 is

Code: Select all

	$newdate = mktime (0,0,0,$month,$nday,$year);
which is inside

Code: Select all

function AddDate ( $month, $day, $year, $numdays) {
	$nday = $day + $numdays;
	$newdate = mktime (0,0,0,$month,$nday,$year);
	return getdate($newdate);
}	
The AddDate function is invoked many places with calls like

Code: Select all

	$ndate = AddDate($mo, $da, $yr, -1);
with the last argument varying (but always numeric).
One entry at line 992 has

Code: Select all

					$tdate = AddDate($pmo, $pda, $pyr, 0); // just to get the name of the day
and the arguments come from

Code: Select all

			for ($col=0; $col<$columns; $col++) {
				$data = $csvarray[$row][$col];      
				if ($col == 0) {
					$pmo = substr($data, 5, 2);
					$pda = substr($data, strrpos($data,"-")+1, 2);
					$pyr = substr($data, 0, 4);
					$tdate = AddDate($pmo, $pda, $pyr, 0); // just to get the name of the day
since the error only comes once (on your system), I suspect it may be the first entry in your CSV that has a different date format than expected.

Try changing

Code: Select all

					$tdate = AddDate($pmo, $pda, $pyr, 0); // just to get the name of the day
to

Code: Select all

 print "<!-- data='$data' pmo='$pmo' pda='$pda' pyr='$pyr' -->\n";
					$tdate = AddDate($pmo, $pda, $pyr, 0); // just to get the name of the day
print "<!-- tdate='$tdate' -->\n";
and it should embed HTML comments in the output that show up with a view-source of the page.

Re: Saratoga Templates with PHP 7

Posted: Thu 22 Feb 2018 11:38 pm
by Mapantz
Changed that..

Code: Select all

[22-Feb-2018 23:37:09 Europe/London] PHP Notice:  A non well formed numeric value encountered in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 1383
[22-Feb-2018 23:37:09 Europe/London] PHP Notice:  Array to string conversion in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 994

Re: Saratoga Templates with PHP 7

Posted: Thu 22 Feb 2018 11:51 pm
by saratogaWX
What is the URL to the WU-History.php and WU-History-inc.php pages?

Re: Saratoga Templates with PHP 7

Posted: Thu 22 Feb 2018 11:54 pm
by ConligWX
saratogaWX wrote:What is the URL to the WU-History.php and WU-History-inc.php pages?
https://warehamwx.co.uk/cumulus/wuhistory/wuhistory.php

Re: Saratoga Templates with PHP 7

Posted: Fri 23 Feb 2018 12:09 am
by saratogaWX
I don't see the extra debugging code in the output (but I do see it in your source), so that instance is not invoked.

It must be one of the other AddDate() calls that is throwing the error.

We fixed the PHP Warning message. The PHP Notice: messages are a nuisance but not harmful. Given that your instance of the script is throwing the Notice errata (but mine is not on PHP 7.2.2 despite having Notice enabled), I don't think I can help further in isolating the issue.. Sorry!

Re: Saratoga Templates with PHP 7

Posted: Fri 23 Feb 2018 12:29 am
by Mapantz
No problems Ken. Like you say, at least the warning has gone. :)

I put

Code: Select all

// Turn off all error reporting
error_reporting(0);
At the top of the page.

Thank you for your help.

Re: Saratoga Templates with PHP 7

Posted: Tue 27 Feb 2018 8:09 am
by ConligWX
Hi Ken

I noticed then mesonet page on my site now has an error this morning.

Code: Select all

Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /path/to/htdocs/weather/mesonet-map-genhtml-inc.php on line 208

Code: Select all

	Line 208: while (list($key, $val) = each($Stations)) { 
	Line 241: while (list($key, $val) = each($Stations)) {
The PHP Manual says that the each() function has been deprecated as of PHP 7.2.0 this means there maybe more than just this instance of each affecting in other webpages.

so should this be correct?

Code: Select all

while (list($key, $val) = each($Stations)) { 
change to:

Code: Select all

foreach($Stations as $key => $val) {

Re: Saratoga Templates with PHP 7

Posted: Tue 27 Feb 2018 5:00 pm
by saratogaWX
Hi Simon,

Yes, that is a good fix for the Deprecated issue. Comments at the PHP docs page even indicate that using foreach is much faster than the while..each() so thats a good thing.

Thanks for finding this.. I'll do an update (and look for more instances in my code).