title: How to override super-class constructor with array parameter in OOP PHP
body: <p>Hello i have a problem in OOP PHP.
  I try override constructor from superclass to subclass with array parameter in it.
  This is my superclass code :</p>
  <pre><code>    &lt;?php
          class Person 
          {
          
              private $firstName;
              private $lastName;
              private $gender;
              private $dob;
              private $address;
              private $country;
              private $phone;
              private $occupation;
              
              public function __construct($array) {
                  foreach($array as $key =&gt; $value) {
                      $this-&gt;$key = $value;
                  }
              }
              
  
                  public function setFirstName($firstName) {
                      $this-&gt;firstName = $firstName;
                  }
  
                  public function getFirstName() {
                      return $this-&gt;firstName;
                  }
              // Another Getter and Setter
              // ...
  </code></pre>
  <p>And this is my subclass code :</p>
  <pre><code>&lt;?php
  
      class Register extends Person
      {
      
          private $nickName;
          private $email;
          
          public function __construct($array) {
              parent::__construct($array);
          }
          
          // Getter and Setter
          // ...
  </code></pre>
  <p>But when i try to access nickName and email, i get an error  like this :</p>
  <pre><code>Fatal error: Cannot access private property Register::$email in C:\xampp\htdocs\php\oop\class\person.class.php on line 16
  </code></pre>
  <p>And this is my test code :</p>
  <pre><code>&lt;?php
      function __autoload($myClass) {
          require_once 'class/' . $myClass . '.class.php';
      }
      
      $data = array(
          'firstname'     =&gt; $_POST['first_name'],
          'lastname'      =&gt; $_POST['last_name'],
          'nickname'      =&gt; $_POST['nick_name'],
          'gender'        =&gt; $_POST['gender'],
          'dob'           =&gt; $_POST['dob'],
          'address'       =&gt; $_POST['address'],
          'zipcode'       =&gt; $_POST['zipcode'],
          'country'       =&gt; $_POST['country'],
          'phone_number'  =&gt; $_POST['phone_number'],
          'email'         =&gt; $_POST['email'],
          'occupation'    =&gt; $_POST['occupation']
      );
      
      
      $account = new Register($data);
      echo $account-&gt;getFirstName();
      
      // Proses DB
      // $db-&gt;insert($account);
      
  ?&gt;
  </code></pre>
  <p>Any Sugesstion?
  Thank you.</p>
  <h1>Answer :</h1>
  <p>I already find solutions. Key name in array must same with class property.
  In array i write <code>firstname</code> and property <code>firstName</code>, the correct way is <code>firstName</code> in both, array and property.</p>