note 33977 added to keyword.paamayim-nekudotayim

From: Date: Sat, 12 Jul 2003 17:15:37 +0000
Subject: note 33977 added to keyword.paamayim-nekudotayim
Groups: php.notes 
Request: Send a blank email to php-notes+get-51975@lists.php.net to get a copy of this message
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(); ---- Manual Page -- http://www.php.net/manual/en/keyword.paamayim-nekudotayim.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33977 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33977&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33977&report=yes

« previous php.notes (#51975) next »