Properties

Properties

In PHP, class member variables are also called properties. These variables are part of the class definition, and are used to represent the state of a class instance (i.e., to differentiate one instance of the class from another). In practice, you may often want to handle the reading or writing of properties in special ways. For example, you may want to always trim a string when it is being assigned to a label property. You could use the following code to achieve this task:

$object->label = trim($label);

The drawback of the above code is that you would have to call trim() everywhere in your code where you might set the label property. If, in the future, the label property gets a new requirement, such as the first letter must be capitalized, you would again have to modify every bit of code that assigns a value to label. The r