Good question.
Firstly, let me say that the concept of an "implicit domain" is one of my pet peeves! The day we universally reject such antiquated conventions will be a glorious day for mathematics.
Thus, my answer is that we should never define a function with just with a formula; always define it by specifying a particular domain and codomain.
For example:
Let $f$ denote the unique function $\mathbb{R}\setminus\{0\} \rightarrow \mathbb{R}$ subject to the following condition. $$f(x) = \frac{x^2}{x}.$$
This is a (not-at-all ambiguous, and therefore perfectly acceptable) shorthand for the following, more long-winded formalization.
Let $f$ denote the unique function $\mathbb{R}\setminus\{0\} \rightarrow \mathbb{R}$ such that for all $x \in \mathbb{R}\setminus\{0\}$, we have the following. $$f(x) = \frac{x^2}{x}.$$
Now lets focus our attention on the expression $x$. There's (at least!) two ways of defining a function using this formula. One way defines a function $g : \mathbb{R} \setminus \{0\} \rightarrow \mathbb{R}$, the other a function $h : \mathbb{R} \rightarrow \mathbb{R}$. These are different functions. The first coincides with $f$; that is, $g=f$. The second does not.
That's basically all there is to it.
Actually, there's one more thing that should really be addressed. Both $f$ and $g$ (they're the same function, after all) can be extended in a unique manner to a continuous function $\mathbb{R} \rightarrow \mathbb{R},$ and this function turns out to be $h$.