public function toArray()
    {
        $hydrator = new ClassMethods();
        $vars = $hydrator->extract($this);
        
        foreach ($vars as $key => &$value) {
            if ($value === null) {
                unset($vars[$key]);
            } elseif (is_object($value) && ! $value instanceof \ArrayObject) {
                if (method_exists($value, 'toArray')) {
                    $value = $value->toArray();
                    if (count($value) == 0) {
                        unset($vars[$key]);
                    }
                } elseif ($value instanceof IsNull) {
                    $vars[$key] = null;
                } elseif ($value instanceof \stdClass) {
                    $vars[$key] = new \stdClass();
                } else {
                    unset($vars[$key]);
                }
            } elseif (is_bool($value)) {
                $vars[$key] = (int) $value;
            }
        }
        
        return $vars;
    }