Chapter

Accessor & Mutator Methods

From ComputerScienceOne by Dr Chris Bourke

Concepts

  1. How do accessor and mutator methods provide access to private member variables?

    "Since we have made all the member variables private, no code outside the class may access or modify their values. It is generally good practice to make member variables private to restrict access. Ho

  2. How can getters and setters validate values before changing private variables?

    "One advantage to using getters and setters (as opposed to naively making everything public) is that you can have greater control over the values that your variables can take. For example, we may want

  3. How can PHP reference a member variable dynamically?

    "You can use the syntax $this->$foo but it will assume that $foo is a string that contains the name of another variable, for example, if $foo = \"firstName\"; then $this->$foo would resolve to the ins

Accessor & Mutator Methods | ComputerScienceOne | Bifalgorithm | Bifalgorithm