Concept
How can PHP reference a member variable dynamically?
ComputerScienceOne / Accessor & Mutator Methods
"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 instance’s $firstName variable. This is useful if your object has been dynamically created by adding variables at runtime that were not part of the original class declaration."
Related Ideas
- How do accessor and mutator methods provide access to private member variables?ComputerScienceOne · Accessor & Mutator Methods
- How do accessor and mutator methods use this to access instance variables?ComputerScienceOne · Accessor & Mutator Methods
- What does the completed PHP Student class look like?ComputerScienceOne · Example
- How does PHP visibility protect class data?ComputerScienceOne · Data Visibility
- How can PHP default values let a constructor accept different numbers of parameters?ComputerScienceOne · Usage
- How do member methods differ from static methods?ComputerScienceOne · Accessor & Mutator Methods
- How do you assign values to variables in PHP?ComputerScienceOne · Using Variables
- How are variables and variable types handled in PHP?ComputerScienceOne · Entry Point & Command Line Arguments