Created
July 31, 2010 11:04
-
-
Save carbolymer/502052 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class RequestType extends SplEnum | |
{ | |
const POST =1; | |
const GET =2; | |
}; | |
class HttpRequest | |
{ | |
public function __construct(RequestType $oType) | |
{ | |
// tutaj uber logika | |
} | |
}; | |
$req = new HttpRequest(RequestType::POST); | |
// itede dalszy ciag programu | |
?> | |
zamiast pisac: | |
<?php | |
define('GET',1); | |
define('POST',2); | |
class HttpRequest | |
{ | |
public function __construct($iType) | |
{ | |
// tutaj walidacja czy iType jest liczba calkowita z przedzialu [1,2], a jak nie to rzucaj wyjatkiem i zarzygaj kibel | |
} | |
}; | |
$req = new HttpRequest(POST); | |
// a co bedzie jak zrobie tak: | |
$req = new HttpRequest(3); | |
// samemu musze zadbac o bledy, podczas gdy jak uzyje enuma, to php za mnie rzuci fatalem, imo ta 2 opcja jest lepsza, bo to wymaga od programisty wiekszej samokontroli i zmniejsza liczbe bledow | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment