PHP Classes

File: class.Error.php

Recommend this page to a friend!
  Classes of marcelo entraigas   Class Error   class.Error.php   Download  
File: class.Error.php
Role: Class source
Content type: text/plain
Description: Main class
Class: Class Error
Keep track of errors in session variables
Author: By
Last change:
Date: 14 years ago
Size: 1,089 bytes
 

Contents

Class file image Download
<?php
/**
 * This class implement a stack of error mesages.
 * <br>Last update: September 20, 2009
 * <br>License: BSD
 * <br>Author: Marcelo Entraigas <marcelo [at] entraigas.com.ar>
 */
class Error {
   
   
/**
     * Set the error message
     *
     * @param string $Error
     */
   
function error($error='', $exit=false){
        if (!isset(
$_SESSION['error']) || !is_array($_SESSION['error']))
           
$_SESSION['error'] = array();
        if(!empty(
$error))
           
$_SESSION['error'][] = $error;
        if(
$exit){
            echo
$this->getErrors();
            exit;
        }
    }
   
   
/**
    * Flush all errors
    */
   
function flushErrors() {
       
$_SESSION['error'] = array();
    }
   
   
/**
    * Returns a string error message
    *
    * @return string
    */
   
function getErrors() {
    if (
$this->countErrors()==0)
        return
'';
   
$html = implode("<br>", $_SESSION['error']);
   
$this->flushErrors();
    return
"<!--Errors--->\n<font face=arial size=3>" . $html . "</font>\n";
    }
   
   
/**
     * Coount the registered errors
     *
     * @return integer
     */
   
function countErrors() {
        return
count($_SESSION['error']);
    }
   
}
?>