Re: PEAR..Errorhandling

From: Date: Wed, 02 Jul 2003 07:40:16 +0000
Subject: Re: PEAR..Errorhandling
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-6373@lists.php.net to get a copy of this message
Peter Valicek - Snr. Cluster Engineer wrote:
Hello Experts, just a little question on pear errorhandling. Following code: require_once 'PEAR.php'; class fruparser extends PEAR {
       /*
        * Constructor
        */
       function fruparser ( $file ) {
               /*
                * Instance of PEAR
                */
               $this->PEAR();
               $this->hash = $this->uniqueID();
               if ( is_file($file) && is_readable($file) ) {
                       $xml = join('', file($file));
                       $this->logging("Read $file to parser");
                       return $this->xmlfile = $xml;
               } else {
                       return $this->errorHandler(1);
               }
       }
/*
        * Error handler function
        */
       function errorHandler ( $errno ) {
               /*
                * set error handler
                */
               $this->setErrorHandling(PEAR_ERROR_DIE);
               /*
                * Array of Errormessages
                */
               $errorcodes = array(
                       '1'  => "Unable to open XML file"
                               );
               $this->logging($errorcodes[$errno]);
               return $this->raiseError($errorcodes[$errno], $errno);
       }
<CODE END> In case function fruparser funs in specified error should not only just be printed "Unable to open XML file" from errorHandler function? Should not $this->raiseError prevent the normal php error message unable to open file? Or does I have misunderstood soemthing. Thanks in forward. -Peter I think you need to supress the native PHP errors by using the @ symbol like:
if ( @is_file($file) && @is_readable($file) ) { .... ... } else { return $this->errorHandler(1); } Also, I think in your class you could simply use a static call to PEAR::raisError(). That way you won't need to extend your class from the PEAR base class IIRC Jeroen

« previous php.pear.general (#6373) next »