Skip to content

Instantly share code, notes, and snippets.

@carbolymer
Created July 31, 2010 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carbolymer/502052 to your computer and use it in GitHub Desktop.
Save carbolymer/502052 to your computer and use it in GitHub Desktop.
<?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