title: PHP constructor with a parameter
body: <p>I need a function that will do something like this:</p>
  
  <pre><code>$arr = array(); // This is the array where I'm storing data
  
  $f = new MyRecord(); // I have __constructor in class Field() that sets some default values
  $f-&gt;{'fid'} = 1;
  $f-&gt;{'fvalue-string'} = $_POST['data'];
  $arr[] = $f;
  
  $f = new Field();
  $f-&gt;{'fid'} = 2;
  $f-&gt;{'fvalue-int'} = $_POST['data2'];
  $arr[] = $f;
  </code></pre>
  
  <p>When I write something like this:</p>
  
  <pre><code>$f = new Field(1, 'fvalue-string', $_POST['data-string'], $arr);
  $f = new Field(2, 'fvalue-int', $_POST['data-integer'], $arr);
  
  // Description of parameters that I want to use:
  // 1 - always integer, unique (fid property of MyRecord class)
  // 'fvalue-int' - name of field/property in MyRecord class where the next parameter will go
  // 3. Data for field specified in the previous parameter
  // 4. Array where the class should go
  </code></pre>
  
  <p>I don’t know how to make a parametrized constructor in PHP.</p>
  
  <p>Now I use a constructor like this:</p>
  
  <pre><code>class MyRecord
  {
      function __construct() {
          $default = new stdClass();
          $default-&gt;{'fvalue-string'} = '';
          $default-&gt;{'fvalue-int'} = 0;
          $default-&gt;{'fvalue-float'} = 0;
          $default-&gt;{'fvalue-image'} = ' ';
          $default-&gt;{'fvalue-datetime'} = 0;
          $default-&gt;{'fvalue-boolean'} = false;
  
          $this = $default;
      }
  }
  </code></pre>