PageRenderTime 18ms CodeModel.GetById 13ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/error.php

https://github.com/t-hebert73/Personal-Website
PHP | 63 lines | 27 code | 8 blank | 28 comment | 1 complexity | bd98550c7bb9e0fcfeab9f33034f7cd7 MD5 | raw file
 1<?php
 2	/**
 3	*	File : Error.php
 4	*	Last Motified : Feb 20, 2012
 5	*	Description : Error class definition, used for error checking.
 6	*				  Requires sessions to work
 7	*/
 8	class Error
 9	{
10		// Member variables
11		private $error;
12		//private $param;
13		
14		// Constructor
15		// Initializes an error
16		// e - A string representing the error
17		public function __construct($e)
18		{
19			// Set the error
20			$this->error = $e;
21		}
22		
23		// Returns the error code
24		public function getError()
25		{
26			// Return the error
27			return $this->error;
28		}
29		
30		// Returns the paremeter
31		// TODO
32		// public function getParam();
33		
34		// Throws an error
35		// This function sets an error for the next page to catch
36		// Note : The errors will remain in the sessions until catched.
37		public function _throw()
38		{
39			// Set the session for the error
40			$_SESSION['error'] = serialize($this);
41		}
42		
43		// Static catch function
44		// Retrieves any errors from the sessions
45		public static function _catch()
46		{
47			// Check to see if there are any errors
48			if( isset($_SESSION['error']) )
49			{
50				// Get the error
51				$e = unserialize($_SESSION['error']);
52				
53				// Delete the session
54				unset($_SESSION['error']);
55				
56				// Return the error
57				return $e;
58			}
59			
60			// No errors found
61			return null;
62		}
63	}