Posts

Showing posts from June 6, 2008

Creating a Class with Properties and Methods

Creating a Class with Properties and Methods on PHP programming example (contoh): A class can be created using code similar to the following: class Foo { var $foo; var $bar; function setBar ($bar) { $this->bar = $bar; } function getBar () { return $this->bar; } } This class has the following characteristics: * The name of the class is 'Foo'. * It contains the variables (properties) '$foo' and '$bar'. * It contains functions (methods) called 'setBar' and 'getBar'. * Function 'setBar' is used to insert data into the object variable '$bar'. * Function 'getBar' is used to retrieve data from the object variable '$bar'. In theory you are supposed to have a 'set' method and a 'get' method for each variable within the class, one to put data in and the other to get data out. These are commonly referred to as 'setters' and 'getters...