-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.php
52 lines (43 loc) · 1.35 KB
/
demo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
require ('Error.php');
$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
// $error->GetErrorCode() get error code (useful if you want to hide sensetive error message for the user)
}
// add errors to a list
$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))
{
// get all errors
foreach ($errors->GetAllErrors() as $err)
{
echo $err['error']."\n"; // echo $err['code'] for error codes
}
}
?>