Back to StateBehaviorTrait class

Method getState

public mixed
getState
(mixed $property = null, mixed $default = null)
Method to get state variables.
Parameters
  • string $property Optional parameter name
  • mixed $default Optional default value
Returns
  • mixed The property where specified, the state object where omitted
Since
  • 4.0.0

Method getState - Source code

/**
 * Method to get state variables.
 *
 * @param   string  $property  Optional parameter name
 * @param   mixed   $default   Optional default value
 *
 * @return  mixed  The property where specified, the state object where omitted
 *
 * @since   4.0.0
 */
public function getState($property = null, $default = null)
{
    if ($this->state === null) {
        $this->state = new CMSObject();
    }
    if (!$this->__state_set) {
        // Protected method to auto-populate the state
        $this->populateState();
        // Set the state set flag to true.
        $this->__state_set = true;
    }
    return $property === null ? $this->state : $this->state->get($property, $default);
}