PHP Classes

PHP Custom Error: Set and get custom application errors

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 142 This week: 1All time: 9,177 This week: 560Up
Version License PHP version Categories
phpcustomerror 1.0.0The PHP License5PHP 5, Language
Description 

Author

This class can set and get custom application errors.

It provides functions to set one or more error messages and error codes.

The class can also return an array with the list of all error messages and codes set during the execution of the current PHP script.

Innovation Award
PHP Programming Innovation award winner
November 2022
Winner
Sometimes PHP applications need to keep track of multiple non-fatal errors that may happen during the execution of the same PHP script.

This package provides a simple class that can keep track of all error messages and codes that happen every time the current PHP script calls the class.

This possibility allows application developers to get a complete list of errors in executing a single script.

Manuel Lemos
Picture of Cedric Maenetja
  Performance   Level  
Name: Cedric Maenetja is available for providing paid consulting. Contact Cedric Maenetja .
Classes: 4 packages by
Country: South Africa South Africa
Age: ???
All time rank: 390722 in South Africa South Africa
Week rank: 33 Up1 in South Africa South Africa Up
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

Example

PHP Custom Error Module

Usage

<?php

    require ('Error.php');

    // SETTING AN ERROR
    // each error is set with an error code and the error message

    $name = 'cet';
    if ($name != 'yung')
    {
        // create a new App/Custom/Error object
        // -1 = error code (you can pass/define your own error codes)
        $error = new App\Custom\Error (-1, 'name does not exist');
    }

    // check if an error occured
    if (App\Custom\Error::IsAnError ($error))
    {
        // handle error
        echo 'Error: '. $error->GetError(); // get error message
        // $name->GetErrorCode() get error code (useful if you want to hide sensetive error message for the user)
    }

    // ADDING MULTIPLE ERRORS
    $names = ['yung', 'cet', 'matt'];
    $name1 = 'cedric';
    $name2 = 'ced';
    $name3 = 'ray';

    if (! in_array ($name1, $names)) $errors = new App\Custom\Error (-1, "$name1 does not exist"); // create a new App/Custom/Error object
    if (! in_array ($name2, $names)) $errors->AddError (-1, "$name2 does not exist"); // add another error
    if (! in_array ($name2, $names)) $errors->AddError (-1, "$name3 does not exist"); // add another error
    
    // check for errors
    if (App\Custom\Error::IsAnError ($errors))
    {
        // $errors->GetAllErrors() get all errors, this returns an array
        foreach ($errors->GetAllErrors() as $err)
        {
            echo $err['error']."\n"; // echo $err['code'] for error codes
        }
    }
?>


  Files folder image Files  
File Role Description
Accessible without login Plain text file demo.php Example Example script
Plain text file Error.php Class Class source
Accessible without login Plain text file README.md Example Example script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:142
This week:1
All time:9,177
This week:560Up