11
votes

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?

3

3 Answers

3
votes

No there isn't. PEAR::isError is legacy from PHP 4 times.

If changing the error level in php.ini is not enough you should check

  • whether there is another php.ini file being loaded (check phpinfo() output via Apache)
  • some script sets the error level.

If all that doesn't help, set an appropriate level using the error_level() function at runtime, or if nothing else helps, suppress the errors using the @ operator. Using @ should be avoided as it is relatively "slow" (error reporting is slow anyways ...) and it might hide other errors.

Long-term suggestion would be to use more modern libraries.

16
votes

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!
    ...
}
5
votes

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.