Home > php > quick import constructor

quick import constructor

This snipplet shows how to automatic import parameters into a class, restricted to the variables defined in the head of the class.

class Demo
{
  var $a, $b, $c
 
  function Demo($data)
  {
    while(list($key,$value)=each($data)){
      if(isset($this->$key)){
        $this->$key = $value;
      }
    }
  }
}
  1. No comments yet.
  1. No trackbacks yet.