title: How to place a function inside a __construct() in PHP
body: <p>I would like to create an object, but i'm a beginner at OOP, tried the code below and it returns the error code:</p>
  
  <p><strong>Parse error: syntax error, unexpected '(', expecting '&amp;' or variable (T_VARIABLE) in /home/acosor/work/bpideeas/branches/testing/clasa/clasa.php on line 25</strong></p>
  
  <p>Basically I would want to insert a function inside a construct, can't really wrap my head around how to do it.</p>
  
  <pre><code>&lt;?php
  
      $clasa = array(
          'e1' =&gt; array('nume' =&gt; 'Nitu', 'prenume' =&gt; 'Andrei', 'sex' =&gt; 'm', 'varsta' =&gt; 23),
          'e2' =&gt; array('nume' =&gt; 'Nae', 'prenume' =&gt; 'Ionel', 'sex' =&gt; 'm', 'varsta' =&gt; 27),
          'e3' =&gt; array('nume' =&gt; 'Noman', 'prenume' =&gt; 'Alice', 'sex' =&gt; 'f', 'varsta' =&gt; 22),
          'e4' =&gt; array('nume' =&gt; 'Geangos', 'prenume' =&gt; 'Bogdan', 'sex' =&gt; 'm', 'varsta' =&gt; 23),
          'e5' =&gt; array('nume' =&gt; 'Vasile', 'prenume' =&gt; 'Mihai', 'sex' =&gt; 'm', 'varsta' =&gt; 25)
      );
  
      $obj = new stdClass();
      foreach ($clasa as $key =&gt; $value) {
          $obj -&gt; $key = $value;
      }
  
      class Clasa {
          function filtru($x, $a, $b) {
              foreach($x as $elev =&gt; $arr) {
                  if($arr[$a] == $b) {
                      echo $arr['nume'].' '.$arr['prenume'].' '.$arr['varsta'].'&lt;br/&gt;';
                  }//if end
              }//foreach end
          }//function end
  
          public function __construct(filtru($x, $a, $b)) {
              $this -&gt; lista = $x;
              $this -&gt; cheie = $a;
              $this -&gt; valori = $b;
          }
      }//class end
  
      $z = new Clasa($clasa, 'sex', 'm');
  
      echo $z;
  
  ?&gt;
  </code></pre>