confirm/PhpZabbixApi

Cannot redeclare class ZabbixApiAbstract

root-ua opened this issue · 6 comments

Hello, I have an error while using ZabbixApi.
PHP Fatal error: Cannot redeclare class ZabbixApiAbstract in /web/zabbix/api/ZabbixApiAbstract.class.php on line 42
Zabbix version: 2.4.3
PHP version: PHP 5.6.5 Zend Engine v2.6.0 with Zend OPcache v7.0.4-dev
FreeBSD 10.1
Compilation process finished without errors:
php build.php
BUILT: abstract class file "build/ZabbixApiAbstract.class.php"
SKIPPED: concrete class file "build/ZabbixApi.class.php"

P.S. It seems to be this bug: https://bugs.php.net/bug.php?id=68698
I will try to disable OpCache :(

Hi

How do you load the class files? Via SPL autoloader or via include/require statements?

Cheers
Domi

I've disabled OpCache but the problem still exist.
I load the class files as it was shown in examples, via include.

I don't think it has anything to do with OpCache.
Are you sure you're not loading the class twice, because if I'm testing it, everything works as expected:

root@pan:/tmp/PhpZabbixApi# php build.php 
BUILT: abstract class file "build/ZabbixApiAbstract.class.php"
BUILT: conrete class file "build/ZabbixApi.class.php"
root@pan:/tmp/PhpZabbixApi# cat<<EOF>test.php
> <?php
> require 'build/ZabbixApi.class.php';
> ?>
> EOF
root@pan:/tmp/PhpZabbixApi# php test.php
root@pan:/tmp/PhpZabbixApi#

Try to load only ZabbixApi.class.php without ZabbixApiAbstract.class.php, or use include_once / require_once instead of include / require:

...
require_once 'ZabbixApiAbstract.class.php';
require_once 'ZabbixApi.class.php';
...

Yes, that's right. I've changed to 'require_once' and this error disappeared. But nowI have another one:
[mgmt]# php sms.php
PHP Warning: fopen(http://127.0.0.1/zabbix/api_jsonrpc.php): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error
in /mgmt/web/mgmt/zabbix/api/ZabbixApiAbstract.class.php on line 244
Could not connect to "http://127.0.0.1/zabbix/api_jsonrpc.php"

In nginx log:
2015/03/13 22:03:04 [error] 1454#0: *165092 FastCGI sent in stderr: "PHP message: PHP Fatal error: Cannot redeclare zbx_err_handler() (previously declared in /zabbix/include/classes/core/ZBase.php:273) in /zabbix/include/classes/core/ZBase.php on line 273" while reading response header from upstream, client: 127.0.0.1, server: 127.0.0.1, request: "POST /zabbix/api_jsonrpc.php HTTP/1.0", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "127.0.0.1"

I have the same problem here:

[Fri Apr 03 00:46:00 2015] [error] [client 172.16.104.73] PHP Fatal error: Cannot redeclare class ZabbixApiAbstract in /u01/html/phpzabbixapi/build/2.4/ZabbixApiAbstract.class.php on line 43

PHP 5.3.3 (cli) (built: Oct 30 2014 20:12:53)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

Zabbix version 2.4.3

@root-ua I think this is a Zabbix internal error and not an PhpZabbixApi related error. Because we don't use the zbx_err_handler function/class in our PhpZabbixApi library.

@rlljorge please use require_once instead of require or simply don't load the abstract class file at all (it will automatically be loaded by ZabbixApi.class.php).