<? PHP
Class phone
{
// Private Field
Private $ number;
Private $ color;
// Constructor (MAGIC method) and initialize the default value
Function _ construct ($ number = '000000', $ color = 'black ')
{
$ This-> Number = $ number;
$ This-> color = $ color;
}
// Value
Public Function _ Get ($ proname)
{
Return $ this-> $ proname;
}
// Assign values (two parameters are received, that is, field names and values)
Public Function _ set ($ proname, $ provalue)
{
$ This-> $ proname = $ provalue;
}
Public Function show ()
{
// The field is called here, instead of the value obtained through the _ Get () method.
Echo 'show (): '. $ this-> number.' <br/> ';
Echo 'show (): '. $ this-> color.' <br/> ';
}
}
// Object
$ P = new phone ();
// Assign a value
$ P-> Number = '123 ';
// Directly output attributes (values)
Echo $ p-> color. '<br/> ';
// Call Method
$ P-> show ();