private function scalar($var)
    {
        if (($this->flags & self::ESCAPE) && is_string($var)) {
            return htmlentities($var, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
        }

        return ($this->flags & self::TOSTRING) && ! is_string($var)
            ? $this->scalar((string) $var)
            : $var;
    }