confirm / PhpZabbixApi

A PHP library for the Zabbix™ JSON-RPC API.
MIT License
114 stars 62 forks source link

PHP 7.4.4 Deprecated: array_key_exists #56

Closed hugleo closed 4 years ago

hugleo commented 4 years ago

PHP Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in /home/hgl/API/vendor/confirm-it-solutions/php-zabbix-api/build/ZabbixApiAbstract.class.php on line 360

phansys commented 4 years ago

Thank you so much for the report! Could you please share the stack trace for this warning? AFAIK, in this package the only call to array_key_exists() is placed at userLogin(), and this method is called from `__construct(), where the type passed as argument 1 is an array.

hugleo commented 4 years ago

confirm-it-solutions/php-zabbix-api/build/ZabbixApiAbstract.class.php line 360

if(array_key_exists('error', $this->responseDecoded))
   throw new Exception('API error '.$this->responseDecoded->error->code.': '.$this->responseDecoded->error->data);

Is not an functionality error, just deprecated warning.

phansys commented 4 years ago

Which version are you using? This should be fixed in 2.4-dev: https://github.com/confirm/PhpZabbixApi/blob/fc81d5e195bc75f7f91b4862d3c3af15bb342cea/build/templates/abstract.tpl.php#L346-L353

Could you please confirm?

hugleo commented 4 years ago

was using v2.4.6

[hgl@hgl API]$ rm -r vendor/ [hgl@hgl API]$ [hgl@hgl API]$ composer require 'confirm-it-solutions/php-zabbix-api:^2.4' ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 1 install, 0 updates, 0 removals

phansys commented 4 years ago

Sorry @hugleo. You need to compile (php ./build/build.php) the development version from local Zabbix sources. I'll try to find time in order to make a stable release this or next week.

Karsonito commented 4 years ago

Is there any release with fix for deprecated warning? Not master which is currently under development Something like 2.4.7 only with fix for 2.4.6

phansys commented 4 years ago

Not yet @Karsonito. I'm sorry, but I didn't found time to provide the fix. I think the right approach will be to have a separate repository for the builder and leave this one just for the resulting SDK and its releases.

phansys commented 3 years ago

@hugleo, @Karsonito; could you please try the 3.x version?

composer require confirm-it-solutions/php-zabbix-api:^3.0@dev

I'll be waiting for your feedback. Thank you.

hugleo commented 3 years ago

That happens when I try to use the dev lib:

require_once DIR.'/lib/vendor/autoload.php'; use ZabbixApi\ZabbixApi; use ZabbixApi\Exception;

[Mon May 31 11:53:40.411316 2021] [php:error] [pid 2883271] [client x.x.x.x:44254] PHP Fatal error: Uncaught Error: Class "ZabbixApi\ZabbixApi" not found in /app/app.php:29\nStack trace:\n#0 {main}\n thrown in /app/app.php on line 29, referer: x.x.x.x

hugleo commented 3 years ago

also tried:

composer require confirm-it-solutions/php-zabbix-api:^2.5

[InvalidArgumentException]
Package confirm-it-solutions/php-zabbix-api at version ^2.5 has a PHP requirement incompatible with your PHP version, PHP extensions and Composer version

But that is because I'm already using php version 8.0.x.

However I'm using 2.4 version with success for php 8. I just fix some errors/warnings in code by hand.

phansys commented 3 years ago

[Mon May 31 11:53:40.411316 2021] [php:error] [pid 2883271] [client x.x.x.x:44254] PHP Fatal error: Uncaught Error: Class "ZabbixApi\ZabbixApi" not found in /app/app.php:29\nStack trace:\n#0 {main}\n thrown in /app/app.php on line 29, referer: x.x.x.x

Thank you for your quick response. Please, take a look to the upgrade path from 2.x to 3.0. Let me know if you need further support.

hugleo commented 3 years ago

Now I got unauthorised access for token zabbix version: Zabbix 5.2.6.

$decoded = base64_decode($_COOKIE['zbx_session']); $ar = json_decode($decoded, true); $zbx_sessionid = $ar['sessionid'];

$api = new ZabbixApi($zabbixUrl . '/api_jsonrpc.php', '', '', '', '', $zbx_sessionid);

PHP Fatal error: Uncaught Confirm\ZabbixApi\Exception: Not authorised.

phansys commented 3 years ago

PHP Fatal error: Uncaught Confirm\ZabbixApi\Exception: Not authorised.

Based on this bug, I just merged #72 :persevere: Could you please give a try to these changes on your environment?

hugleo commented 3 years ago

success!!!

phansys commented 3 years ago

Great! Thank you very much for your time and sorry for the round trips.