sol1 / icingaweb2-module-netbox

Netbox importer for director, and integration with netbox
28 stars 6 forks source link

Creation of dynamic properties deprecated in PHP 8.2 #26

Closed vk2amv closed 10 months ago

vk2amv commented 10 months ago

Using this plugin on a new Icinga server running Debian 12 and PHP 8.2 from the Debian repos.

Getting this error when going to Import Source, select an import source and then Preview.

Deprecated : Creation of dynamic property Icinga\Module\Netbox\Netbox::$baseurl is deprecated in /usr/share/icingaweb2/modules/netbox/library/Netbox/Netbox.php on line 23

Deprecated : Creation of dynamic property Icinga\Module\Netbox\Netbox::$token is deprecated in /usr/share/icingaweb2/modules/netbox/library/Netbox/Netbox.php on line 24

And lots more of that.

This is due to the creation of dynamic properties being deprecated in PHP 8.2. https://www.php.net/manual/en/migration82.deprecated.php

This will become an error exception in PHP 9.0 and will get removed completely at some point in the future.

A hacky work around is to add the attribute

[\AllowDynamicProperties]

directly above the Netbox class

// use Icinga\Module\Director\Daemon\Logger;

[\AllowDynamicProperties]

class Netbox {

That resolved the issue for me.

According to the PHP 8.2 documentation the long term solution is to declare all used properties in the class declaration.

sol1-matt commented 10 months ago

Thanks @afoster, this has been tested and works.

@vk2amv you should be able to get rid of the hack above with the release v3.6.1.0