Ask a Question related to PHP Notes, Design and Development.
-
jpipes1@columbus.rr.com #1
note 33977 added to keyword.paamayim-nekudotayim
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 -- [url]http://www.php.net/manual/en/keyword.paamayim-nekudotayim.php[/url]
Edit Note -- [url]http://master.php.net/manage/user-notes.php?action=edit+33977[/url]
Delete Note -- [url]http://master.php.net/manage/user-notes.php?action=delete+33977&report=yes[/url]
Reject Note -- [url]http://master.php.net/manage/user-notes.php?action=reject+33977&report=yes[/url]
jpipes1@columbus.rr.com Guest
-
note 33819 added to keyword.parent
Which versions of PHP support the "parent::"? Most of the other OOP related stuff includes info about required PHP version but for some reason this... -
note 33724 added to keyword.parent
There is a difference between PHP and C# managing the overloaded variables of the parent class: class a{ var $a=1; function display(){ echo... -
note 33702 added to keyword.extends
Just a simple example about inheritance: class a1{ var $a=10; function a1($a){ $this->a=$a; } } class a2 extends a1{ -
note 31265 deleted from keyword.parent by didou
Note Submitter: emmix -> emmix@wa.home.pl ---- Problem comprehension the class extends and inheritance variables: class A { var $x;... -
note 31073 deleted from keyword.extends by didou
Note Submitter: eschatus@eschatus.com ---- As Zend seems not to include multiple inheritance available in the Zend 2.0 engine, I've made a...



Reply With Quote

