title: Zend Framework 2 - Magic Getter and Setter for Doctrine and Annotation forms
body: <p>I read about a magic getter- and setter function which supersede the huge plie of standard getters and setters. (<a href="http://milesj.me/blog/read/minimal-class-getset" rel="nofollow">Link</a>)</p>
  
  <p>I altered the function of Miles because I'm using <code>AnnotationForms</code> and don't want the underscore in the variables like <code>$_name</code>. I updated the magic functions but when trying to call e.g. <code>getName()</code> I get:</p>
  
  <blockquote>
    <p>Fatal error: Call to undefined method ... Entity::getName()</p>
  </blockquote>
  
  <p>Here's my code:</p>
  
  <pre><code>&lt;?php
  namespace Entity;
  use Doctrine\ORM\Mapping as ORM;
  use Zend\Form\Annotation as Form;
  
  /**
   * @ORM\Entity
   * @ORM\Table(name="masterdata_entity")
   * @Form\Name("entity")
   * @Form\Attributes({ "class": "form-horizontal" })
   * @Form\Hydrator("Zend\Stdlib\Hydrator\ObjectProperty")
  */
  class Entity
  {
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     * @Form\Exclude()
     */
    protected $id;
    /**
     * @ORM\Column(type="string")
     * @Form\Filter({"name":"StringTrim"})
     * @Form\Validator({"name":"StringLength", "options":{"min":1, "max":50}})
     * @Form\Attributes({"type":"text"})
     * @Form\Options({"label":"Name"})
     */
    protected $name;
  
  public function __get($property) {
      return (isset($this-&gt;{$property}) ? $this-&gt;{$property} : null);
  }
  
  public function __set($property, $value) {
      if (isset($this-&gt;{$property})) {
          $this-&gt;{$property} = $value;
      }
  }
  
  public function __isset($property) {
      return isset($this-&gt;{$property});
  }
  
  }
  </code></pre>
  
  <p>Any ideas why that is and how I can fix it?</p>