title: Object Oriented PHP Best Practices
body: <p>Say I have a class which represents a person, a variable within that class would be $name.</p>
  
  <p>Previously, In my scripts I would create an instance of the object then set the name by just using:</p>
  
  <pre><code>$object-&gt;name = "x";
  </code></pre>
  
  <p>However, I was told this was not best practice? That I should have a function set_name() or something similar like this:</p>
  
  <pre><code>function set_name($name)
  {
      $this-&gt;name=$name;
  }
  </code></pre>
  
  <p>Is this correct?</p>
  
  <p>If in this example I want to insert a new "person" record into the db, how do I pass all the information about the person ie $name, $age, $address, $phone etc to the class in order to insert it, should I do:</p>
  
  <pre><code>function set($data)
  {
      $this-&gt;name= $data['name'];
      $this-&gt;age = $data['age'];
      etc
      etc
  
  }
  </code></pre>
  
  <p>Then send it an array? Would this be best practice? or could someone please recommend best practice?</p>