<?php

// ...

class Foo
{
    // ...

    static public function fromArray(array $data)
    {
        $o = new self();
		
        $reflection = new \ReflectionClass($o);
        $properties = $reflection->getProperties();
        $properties = array_map(function ($v) { /* @var $v \ReflectionProperty */
            return str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($v->getName()))));
        }, $properties);
		
        if (array_key_exists('id', $properties)) { unset($properties['id']); }
		
        foreach ($properties as $k) {
            $setter = sprintf('set%s', ucwords($k));
			
            if (array_key_exists($k, $data) && method_exists($o, $setter)) {
                $o->{$setter}($data[$k]);
            }
        }
		
        return $o;
    }

    // ...
}

?>