AndrewFarley / PHP-Zabbix-API

A PHP-based API for consuming the Zabbix API
17 stars 6 forks source link

API calls fail unless debugEnabled is called first #1

Open walterheck opened 12 years ago

walterheck commented 12 years ago

Unless I call ZabbixAPI::debugEnabled(FALSE); first, any API calls fail. See:

<?
  include_once("lib/php/ZabbixAPI.class.php");
  ZabbixAPI::debugEnabled(FALSE);
  # log in to the api
  ZabbixAPI::login('http://192.168.56.101', 'admin', 'zabbix')
    or die('Unable to login: ' . print_r(ZabbixAPI::getLastError(), TRUE));

gives:

> php test.php 
> echo $?
0

whereas:

<?
  include_once("lib/php/ZabbixAPI.class.php");
  // ZabbixAPI::debugEnabled(FALSE);
  # log in to the api
  ZabbixAPI::login('http://192.168.56.101', 'admin', 'zabbix')
    or die('Unable to login: ' . print_r(ZabbixAPI::getLastError(), TRUE));

gives:

> php test.php 
Fatal error: Call to undefined method stdClass::__login() in ~/Source/zabbix-cookbook/Code/lib/php/ZabbixAPI.class.php on line 101
walterheck commented 12 years ago

Also:

> php -v
PHP 5.3.13 with Suhosin-Patch (cli) (built: Jun 20 2012 17:05:20) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
> uname -a
Darwin walterheck-mbp.local 12.0.0 Darwin Kernel Version 12.0.0: Sun Jun 24 23:00:16 PDT 2012; root:xnu-2050.7.9~1/RELEASE_X86_64 x86_64
aprepo commented 11 years ago

Same problem.

My setup is

php -v PHP 5.3.10 (cli) (built: Dec 13 2012 22:30:08) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

jansennerd10 commented 9 years ago

This is because the internal __init() function is not correctly detecting whether the API was already initialized. To fix this, change line 191 from

if (get_class(self::$instance) != "ZabbixAPI")

to

if(!(self::$instance instanceof ZabbixAPI))
lazylionca commented 6 years ago

Fixed in Fork.

AndrewFarley commented 6 years ago

@lazylionca Feel free to submit a PR, I'll merge it in here