Tutorials

31.01.2008 13:49 Alter: 4 yrs

vTiger CRM5 and PHP 5.2

Rubrik: Tutorials
Von: Sebastian Koch

PHP 5.2 indroduces a new error

Starting with PHP 5.2 you cannot convert an object to string anymore. In former PHP versions echo 'Object: '.$object;

was working now this throws a Catchable fatal error. The output looks like this:

Catchable fatal error: Object of class <ClassName> could not be converted to string in /var/www/xxx on line yyy

Many older scripts will have problems with this, the solution below is specifically for vTiger CRM 5. But with a few changes you can use it with any other script producing the error described above.

Solution

PHP allows you to catch some errors using an error handler. SO we can define an error handler that just catches our fatal error and does nothing else. Create a file called "ErrorHandler.php" in your vTiger root dir and add the following lines:

<?php
function compatibilityErrorHandler($errno, $errstr, $errfile, $errline)
{
  switch ($errno) {
  case  E_RECOVERABLE_ERROR:
    break;
  default:
    echo "Unknown error type: [$errno] $errstr
\n";
    break;
  }
}

// set to the user defined error handler
$old_error_handler = set_error_handler("compatibilityErrorHandler", E_RECOVERABLE_ERROR);
?>

Now add the line

 

require_once('ErrorHandler.php');

in "config.inc.php" below the comments before

include('vtigerversion.php');

 

Now your script should run without showing any catchable errors!

Rechtliches

Jegliche Haftung der ilexius GmbH bei Verwendung der dargestellten Software oder Vorgehensweisen ist ausgeschlossen. Die ilexius GmbH haftet nicht für mögliche Schäden die durch die Verwendung dieses Dokuments entstehen.

Das Dokument unterliegt dem Copyright der ilexius GmbH. Sollten Sie unsicher sein bzgl. der Nutzung dieses Dokuments wenden Sie sich an die Ansprechpartner des Dokuments.