note 33977 deleted from keyword.paamayim-nekudotayim by jmoore
| From: | jmoore@php.net | Date: | Sun, 13 Jul 2003 09:22:55 +0000 |
| Subject: | note 33977 deleted from keyword.paamayim-nekudotayim by jmoore | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-52017@lists.php.net to get a copy of this message | ||
Note Submitter: jpipes1@columbus.rr.com
----
A great way to implement enums in PHP is to use the :: operator. For instance, if I had a class
FormField, with a member variable $Type, I could implement this structure:
/* Enum for FormFieldType */
class FormFieldType {
var $Textbox = 0;
var $Password = 1;
// and so on...
}
class FormField {
var $Type; // expects FormFieldType
// More properties and functions
// Constructor
function FormField( $fft ) {
$this->Type = $fft;
}
function ToString() {
$sHTML = '';
switch ($this->Type) {
case: FormFieldType::Textbox:
//implement Textbox HTML...
break;
case: FormFieldType::Password:
//implement Password HTML...
break;
}
return $sHTML;
}
}
/* usage */
$oField =& new FormField(FormFieldType::Textbox);
$oField->ToString();