PHP OOP using setter and getter methods on form elements
<p>I'm coming from Java programming and I know a little when it comes with PHP OOP style. In <strong>Java Server Faces</strong> I got used with <strong>setters</strong> and <strong>getters</strong> which I use to set values of fields from data entered on form.</p>

<p>So for instance, </p>

<p><strong>Person.java</strong></p>

<pre><code>Class Person{
    private String firstname;
    public setFirstName(String aFirstName){
        this.firstname = aFirstName;
    }
    public getFirstName(){
        return this.firstname;
    }
}
</code></pre>

<p><strong>PersonForm.xhtml</strong></p>

<p><strong>First Name:</strong> <code>&lt;input type="text" name="firstname" value="#{person.firstname}"/&gt;</code></p>

<p><code>#{person.firstname}</code> is what calls the <code>setFirstName();</code> method from the class <strong>Person</strong></p>

<p>So I did some google to see how it's done in PHPs OOP style.</p>

<p>So on PHP I thought it would look something like this.</p>

<p><strong>Person.php</strong></p>

<pre><code>class Person{
    private $firstname;
    public function setFirstName($aFirstName){
         $this-&gt;firstname = $aFirstName;
    }

    public function getFirstName(){
         return $this-&gt;firstname;
    }
}
</code></pre>

<p><strong>PersonForm.php</strong></p>

<pre><code>&lt;?php
   $person = new $Person();
?&gt;
&lt;form&gt;
First Name: &lt;input type="text" name="firstname" value="&lt;?php echo $person-&gt;firstname ?&gt;"/&gt;
&lt;/form&gt;
</code></pre>

<p>I want to store the value entered on input text field using the setFirstName() method of Person class.</p>

<p>Does writing the <code>value="&lt;?php echo $person-&gt;firstname ?&gt;"</code> call the <code>setFirstName()</code> method?
Or should I do <code>value="&lt;?php echo $person-&gt;setFirstName() ?&gt;"</code>?</p>

<p>I'd appreciate any explanation or example.
PHPs OOP style is very similar with Java that's why I decided to study PHP using the OOP style instead of procedural.</p>

<p>Thank you.</p>