WXforum.net
Web Weather => Weather Website PHP/AJAX scripting => Custom Website Templates => Topic started by: mexbound on June 07, 2021, 11:48:28 AM
-
This morning I tried upgrading my godaddy hosting to PHP8. I then tried my wxindex.php and it didn't get very far. My site is not live so that is why I tried going to PHP8. I have lots of time to debug it but I have to admit I do not know alot about PHP debugging. Where can I find an error log to start looking at?
Here is the site with PHP8: https://ajijicweather.com/wxindex.php
Any help getting me started is greatly appreciated.
-
It looks like something in ajax-dashboard6.php is blowing up. Are you running the updated 6.95d version?
If not, try installing these updated versions and support scripts (attached).
Also, check the error_log on your site for details about PHP Fatal Errors -- if your site uses cPanel, there's a cPanel viewer for the error_log, otherwise, the error_log will be found in the same directory as the Apache access_log files for your website.
You can also try my ajax-dashboard6.php with debugging enabled here (https://saratoga-weather.org/weewx/ajax-dashboard6.php?sce=view).
-
Ok, starting to get some progress here. Thanks for the input.
This was my first problem I encountered. month and mday needed single quotes around them, Made that change in AltAjaxDashboardConfig6.php to this:
$month = $today['month'];
$day = $today['mday'];
I got further into the code.
Then I get this and not sure how to change it:
Fatal error: Uncaught Error: Attempt to assign property "date" on null in /home/mxo4kz4ohhnx/public_html/ajax-dashboard6.php:3461 Stack trace: #0 /home/mxo4kz4ohhnx/public_html/ajax-dashboard6.php(1336): getMoonInfo() #1 /home/mxo4kz4ohhnx/public_html/wxindex.php(70): include_once('/home/mxo4kz4oh...') #2 {main} thrown in /home/mxo4kz4ohhnx/public_html/ajax-dashboard6.php on line 3461
Line 3461 is:
@$info->date = $date;
And the following is directly from error_log:
[07-Jun-2021 13:40:56 America/Los_Angeles] PHP Fatal error: Uncaught Error: Attempt to assign property "date" on null in /home/mxo4kz4ohhnx/public_html/ajax-dashboard6.php:3461
Stack trace:
#0 /home/mxo4kz4ohhnx/public_html/ajax-dashboard6.php(1336): getMoonInfo()
#1 /home/mxo4kz4ohhnx/public_html/wxindex.php(70): include_once('/home/mxo4kz4oh...')
#2 {main}
thrown in /home/mxo4kz4ohhnx/public_html/ajax-dashboard6.php on line 3461
-
To fix the fatal error in ajax-dashboard6.php, change
@$info->date = $date;
to $info = new STDclass;
@$info->date = $date;
PHP8 got a bit fussy and won't instantiate a default class on first use if previously undefined (unlike prior PHP versions). Adding the ' $info = new STDclass; ' fixes that issue by explicitly instantiating the class.
-
Thanks a bunch for explaining that. You certainly have a good grasp of PHP.
So I made the change you showed me and it got me by that error.
It made it further along until this:
[08-Jun-2021 11:02:22 America/Mexico_City] PHP Fatal error: Uncaught TypeError: abs(): Argument #1 ($num) must be of type int|float, string given in /home/mxo4kz4ohhnx/public_html/ajax-dashboard6.php:2298
Stack trace:
#0 /home/mxo4kz4ohhnx/public_html/ajax-dashboard6.php(2298): abs()
#1 /home/mxo4kz4ohhnx/public_html/wxindex.php(70): include_once('/home/mxo4kz4oh...')
#2 {main}
thrown in /home/mxo4kz4ohhnx/public_html/ajax-dashboard6.php on line 2298
I am using all the AltDashboard_updates.zip you attached in post#2, so I have all the latest. One other thing I notice is I get a message that it cannot find my clientraw.txt file. I have the location for it set in Settings-weather.php: $SITE['clientrawfile'] = './WD_realtime/clientraw.txt'; // directory and name of Weather-Display realtime.txt file.
edit: I was able to figure out why it wasn't finding my clientraw.txt file so that is not an issue.
-
I was able to get around the "Uncaught TypeError: abs(): Argument #1 ($num) must be of type int|float," error by adding a settype line of code before the abs().
<?php settype($sevendayet,"float"); ?>
<span class="convRain"><?php echo abs($sevendayet) . $uomRain; ?> </span>
Not sure if this was the best method, but it works.
My next error is now in cloud-base.php. I am using the cloud-base.php you supplied in the zip file in post #2. I must be blind because I can't figure this one out:
[09-Jun-2021 16:28:32 UTC] PHP Parse error: syntax error, unexpected token "," in /home/mxo4kz4ohhnx/public_html/cloud-base.php on line 863
if (match($imgMist,$clouds["pic"])) { <<<<<<<<<<<<<<< line 863
$pt = $cldhgt==0?200:170;
$cY = $pt - $clouds["base"] - round($cldhgt/$scale["step"]);;
} else {
$pt = 170 - round($cldhgt/$scale["step"]);
$cY = $pt - $clouds["base"];
}
https://ajijicweather.com/wxindex.php
-
PHP 8.0 introduced function match()
... but that snippet is incorrect syntax / use of it :roll:
-
Thanks for that Beteljuice! The cloud-base.php already had a function named match() defined in it and now that PHP 8 has it's own function, that was causing the problem. I redefined the "match()" function in cloud-base.php to "cloud_match()" and changed all the places referring to it. Everything is working now. Woo-hoo!
-
So it looks like I have made all the changes necessary to run the templates on PHP 8. Here is a summary of the changes from the posts above:
1. In AltAjaxDashboardConfig6.php - changed month and mday, they needed single quotes around them:
$month = $today['month'];
$day = $today['mday'];
2. In ajax-dashboard6.php - added a "STDclass" line above the line @$info->date = $date;
$info = new STDclass;
@$info->date = $date;
3. In ajax-dashboard6.php - added a "settype" line above the line <span class="convRain"><?php echo abs($sevendayet) . $uomRain; ?> </span>
<?php settype($sevendayet,"float"); ?>
<span class="convRain"><?php echo abs($sevendayet) . $uomRain; ?> </span>
4. In cloud-base.php - changed the function named match( ) to a new name of cloud_match( ) and changed all references of match( ) to cloud_match( ).
I'm currently doing some detail testing but all the main template files seem to be working correctly.
I do have some problems with PHP8 and the "Murray" wxtempdetail.php (and subsequent scripts). Will post in a different thread.
-
I found one more PHP8 change I needed to make. In cloud-base.php, line 1162, variable $metRainStopped is undefined. I defined it in the GLOBAL just above it and the error went away.