Skip to content

Fix PHP 8.5 compatibility issues - #248

Merged
TheWitness merged 9 commits into
Cacti:developfrom
BridgelineTech:fix-php85-compatibility
Sep 20, 2026
Merged

TheWitness merged 9 commits into
Cacti:developfrom
BridgelineTech:fix-php85-compatibility

Conversation

@BridgelineTech

Copy link
Copy Markdown
Contributor

This PR fixes several PHP 8.5 compatibility issues encountered while running Cacti Weathermap under PHP 8.5.

The changes address runtime TypeError failures caused by stricter parameter typing in PHP/GD, along with removal of imagedestroy() calls that are deprecated in PHP 8.5 but generate non-blocking log errors.

Changes include:

Cast numeric string values before passing them to round().
Ensure GD image coordinates and dimensions are integers where required.
Store and pass TrueType font sizes as floats.
Ensure find_distance() returns an integer array index.
Guard preg_match() so integer match references are not passed as the subject.
Cast legend coordinates before calling imagecopy().
Ensure thumbnail dimensions are integers.
Remove deprecated imagedestroy() calls. GD images have been GdImage objects since PHP 8.0 and are automatically released when no longer referenced.

These issues were encountered sequentially during actual Weathermap map generation on:

Cacti 1.2.30
PHP 8.5.4
Ubuntu 26.04

After applying these changes, the Weathermap poller successfully completes map generation without PHP 8.5 compatibility warnings or fatal errors:

SYSTEM WEATHERMAP STATS: Time:0.20 Maps:1 Warnings:0 Notes:None

The two separate EOF handling fixes are intentionally not included in this PR, as they have been submitted separately.

@TheWitness TheWitness left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BridgelineTech, can you please this wrapper around imagedestroy()? Otherwise, it looks good.

if (version_compare(PHP_VERSION, '8.5.0', '<')) {
   imagedestroy(blah);
}

@TheWitness

Copy link
Copy Markdown
Member

Copilot is recommending the use of unset(blah) over imagedestry(bhah). That should be the fix I think.

@BridgelineTech

Copy link
Copy Markdown
Contributor Author

Will do... I have a couple of additional fixes in my local for EOF and related that I have not yet submitted as PRs. I will try and get them all packaged up later, including the suggested "unset" vs just deleting. Thanks!

xmacan
xmacan previously approved these changes Sep 19, 2026
imagedestroy() calls were removed for PHP 8.5 compatibility (GD images are
now objects, and imagedestroy() is deprecated), but removing them outright
means these temporary/intermediate images are held until PHP's own refcount
garbage collection reclaims them instead of being released immediately.
Replaced each removed imagedestroy() call with unset() on the same variable
so the reference is dropped right away, matching the original intent.
@TheWitness
TheWitness merged commit 583ebc5 into Cacti:develop Sep 20, 2026
3 checks passed
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

Successfully merging this pull request may close these issues.

5 participants