Search code examples
phpdoctrinenomenclature

accessor and mutator?


when using doctrine i stumble upon these 2 words: accessor and mutator.

are these only used in doctrine or are they specific for php?

and what do they mean?

thanks


Solution

  • They're just fancy terms for getters and setters.

    class MyClass
    {
        private $prop;
    
        // Accessor (or Getter)
        public function getProp()
        {
            return $this->prop;
        }
    
    
        // Mutator (or Setter)
        public function setProp($value)
        {
            $this->prop = $value;
        }
    
    }