Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-static method PEAR::isError() should not be called statically

Tags:

php

static

pear

After upgrading from RHEL 5x to CentOS 6x, I started seeing these errors in my httpd log:

PHP Strict Standards: Non-static method PEAR::isError() should not be called statically in /web/sites/blah/somescript.php on line 33

I saw similar errors for MDB2. More on that in a sec.

somescript.php:

32  $mdb2_dbx = MDB2::factory($dsn_mdb2, $mdb2_options);
33  if (PEAR::isError($mdb2_dbx))
34  {
35      $err = '<p>Cannot connect to database: ' . $mdb2_dbx->getMessage();
36      errorHandler($err);
37  }   

The first thing I did was edit /etc/php.ini and add & ~E_STRICT to error reporting. Restarted httpd to load the new config. Still getting these error messages.

Others mentioned the same problem with MDB2, so I updated these packages to the beta releases. This seemed to address MDB2 errors, but I'm still getting the PEAR error messages in httpd log file.

System info:

# pear list
PEAR               1.9.4   stable
MDB2               2.5.0b5 beta
MDB2_Driver_mysql  1.5.0b4 beta
MDB2_Driver_mysqli 1.5.0b4 beta

# php --version
PHP 5.4.20 (cli) (built: Sep 18 2013 19:55:33) 

# cat /etc/centos-release 
CentOS release 6.4 (Final)

# apachectl -v
Server version: Apache/2.2.15 (Unix)

Question

Is there a different way of invoking PEAR::isError() that will not produce errors?

like image 580
a coder Avatar asked Oct 08 '13 13:10

a coder


2 Answers

I'm afraid @johannes is incorrect - this is very doable. Simply substitute this in your recipe:

if ((new PEAR)->isError($mdb2_dbx)) {
    // Victory! Er, I mean, Error!
    ...
}
like image 102
Winfield Trail Avatar answered Sep 24 '22 21:09

Winfield Trail


It may be worth noting that that calling PEAR::isError($obj) with one argument is equivalent to is_a($obj, 'PEAR_Error'), if you're updating your own code. I know it is not best practice to "unwrap" a library method like that, but it is basically just an "instance of" check.

like image 24
Ulrich Christensen Avatar answered Sep 23 '22 21:09

Ulrich Christensen