Error class speciaal voor jou

Gestart doorMaartenl4 reacties8 weergaven

5 berichten · pagina 1 van 1

Maartenl

Lid · Topicstarter

Berichten
5.897
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo,

Ik heb een error class gemaakt. Een beetje zinloos, maar toch biggrin
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/class"]class[/URL] error
[COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [COLOR= #0000BB]$errors[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [COLOR= #0000BB]$count[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] add[COLOR= #007700]([/COLOR][COLOR= #0000BB]$problem[/COLOR][COLOR= #007700])[/COLOR] [COLOR= #FF8000]// function for adding an error[/COLOR]
    [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/empty"]empty[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$problem[/COLOR][COLOR= #007700]))[/COLOR] [COLOR= #FF8000]// check if $error is not empty[/COLOR]
        [COLOR= #007700]{[/COLOR]
            [COLOR= #FF8000]// do nothing[/COLOR]
        [COLOR= #007700]}[/COLOR]
        [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strlen"]strlen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$problem[/COLOR][COLOR= #007700]) <[/COLOR] [COLOR= #0000BB]5[/COLOR][COLOR= #007700])[/COLOR] [COLOR= #FF8000]// if the error is to short[/COLOR]
        [COLOR= #007700]{[/COLOR]
            [COLOR= #FF8000]// do nothing[/COLOR]
        [COLOR= #007700]}[/COLOR]
        [URL="http://www.php.net/else"]else[/URL]
        [COLOR= #007700]{[/COLOR]
            [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]errors[COLOR= #007700][[/COLOR][COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR][URL="http://www.php.net/count"]count[/URL][COLOR= #007700]] =[/COLOR] [COLOR= #0000BB]$problem[/COLOR][COLOR= #007700];[/COLOR]
            [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR][URL="http://www.php.net/count"]count[/URL][COLOR= #007700]++;
        }
    }[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] countError[COLOR= #007700]()[/COLOR] [COLOR= #FF8000]// returns the number of errors[/COLOR]
    [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR][URL="http://www.php.net/count"]count[/URL][COLOR= #007700];
    }[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] showError[COLOR= #007700]()[/COLOR] [COLOR= #FF8000]// shows the errors[/COLOR]
    [COLOR= #007700]{[/COLOR]
        [COLOR= #0000BB]$returnError[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700];[/COLOR]
        [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]errors [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$error[/COLOR][COLOR= #007700])
        {[/COLOR]
            [COLOR= #0000BB]$returnError[/COLOR] [COLOR= #007700].=[/COLOR] [COLOR= #DD0000]<li>[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$error[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]</li>[/COLOR][COLOR= #007700];
        }[/COLOR]
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$returnError[/COLOR][COLOR= #007700];
    }
}[/COLOR]
[COLOR= #0000BB]$error[/COLOR] [COLOR= #007700]= new[/COLOR] Error[COLOR= #007700]();[/COLOR]
[COLOR= #0000BB]$error[/COLOR][COLOR= #007700]->[/COLOR]add[COLOR= #007700]([/COLOR][COLOR= #DD0000]There is something wrong![/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]// add an error[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$error[/COLOR][COLOR= #007700]->[/COLOR]countError[COLOR= #007700]() !=[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700])[/COLOR] [COLOR= #FF8000]// if there is an error[/COLOR]
[COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]The following errors occurred:[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$error[/COLOR][COLOR= #007700]->[/COLOR]showError[COLOR= #007700]();[/COLOR] [COLOR= #FF8000]// show error[/COLOR]
[COLOR= #007700]}[/COLOR]
?>


Commentaar is altijd welkom.

Groetjes, Maarten
0
Thom

Lid

Berichten
10.654
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Je hebt wel
  • ... maar moet je ook niet ergens
      openen? yummie
  • 0
    Rik

    Lid

    Berichten
    18.393
    Reputatie
    0
    Punten
    0,04
    Lid sinds
    Laatst gezien
    Op lijn 8 maak je $errors aan, maar die gebruik je verder niet. Waarom?

    Ik zou niet "$returnError = The following errors occurred:;" doen. Als iemand een andere tekst wil dan moet dat in de class aangepast worden, en dat wil je niet. Je wilt eigenlijk alleen maar logica in je class.
    0
    Maartenl

    Lid · Topicstarter

    Berichten
    5.897
    Reputatie
    0
    Punten
    0,00
    Lid sinds
    Laatst gezien
    Rik schreef:
    Op lijn 8 maak je $errors aan, maar die gebruik je verder niet. Waarom?

    Ik zou niet "$returnError = The following errors occurred:;" doen. Als iemand een andere tekst wil dan moet dat in de class aangepast worden, en dat wil je niet. Je wilt eigenlijk alleen maar logica in je class.
    Klopt, vergeten weg te halen. Dat had ik toegevoegd maar vergeten weg te halen. Je hebt gelijk.

    Ik pas het aan wink
    0
    Rik

    Lid

    Berichten
    18.393
    Reputatie
    0
    Punten
    0,04
    Lid sinds
    Laatst gezien
    Ziet er verder wel goed uit volgens mij.
    0

    Jouw reactie

    Deel je idee, stel een vraag of help een ander verder.

    Editor laden…

    Praat mee met de One2xs-community.

    Inloggen om te reageren