/** * Recreates object by calling the constructor with parameters * that match the array keys (recursively for objects) * * Requirements: * * 1) Constructor parameters that are objects need to be type hinted * * 2) Constructor parameters that are objects need to implement {@see SerializableInterface} * * 3) Constructor parameter names need to match the class variable names * * @param array $obj * @throws NotSerializableException If a constructor takes an object that * does not implement {@see SerializableInterface} * @return $this */ public static function fromArray($obj) { return SerializeHelper::createClassFromArray(get_called_class(), $obj); }
public function toArray() { return SerializeHelper::serializeObject(get_called_class(), get_object_vars($this)); }