2 Much simpler proof with much weaker hypotheses.

Edit: This one's been bugging me all weekend. I've even gone so far as to look up perfectly normal.

This property holds for perfectly normal spaces. In a perfectly normal space, every closed set is the zero set of a function (to $\mathbb{R}$, and this characterises perfectly normal spaces according to Wikipedia).

Here's the proof. Let $X$ be a perfectly normal space. Let $U \subseteq X$ be an open set, and $f : U \to \mathbb{R}$ a continuous function. Let $r : X \to \mathbb{R}$ be such that the zero set of $r$ is the complement of $U$. Let $s : \mathbb{R} \to \mathbb{R}$ be the function $s(t) = \min\lbrace 1, |t|^{-1}\rbrace$.

The crucial fact is that if $p : U \to \mathbb{R}$ is a bounded function then the pointwise product $r \cdot p : U \to \mathbb{R}$ (technically, $p$ should be restricted to $U$ here) extends to a continuous function on $X$ by defining it to be zero on $X \setminus U$.

From this, the rest follows easily.

• The composition $s \circ f$ is bounded on $U$, hence $r \cdot (s \circ f)$ extends to a continuous function on $X$, say $h$.

• The product $(s \circ f) \cdot f$ is also bounded on $U$, since $(s \circ f)(x) = \min\lbrace 1, |f(x)|\rbrace)$. Hence $r \cdot (s \circ f) \cdot f$ extends to a continuous function on $X$, say $g$.

• As $s(t) \ne 0$ for all $t \in \mathbb{R}$, $(s \circ f)(x) \ne 0$ for all $x \in X$. Hence $h(x) \ne 0$ for all $x \in U$.

• Finally, on $U$, $g(x) = h(x) \cdot f(x)$, whence, as $h$ is never zero on $U$, $f = g/h$ as required.

• This isn't a complete characterisation of these spaces. Essentially, this result holds if there are enough continuous functions (as above) on $X$ and if there are too few.

As an example of the latter, consider a topological space $X$ where every pair of non-trivial open sets has non-empty intersection. Then there can be no non-constant functions to $\mathbb{R}$, either on $X$ or on any open subset thereof. Hence every continuous function on an open subset of $X$ trivially extends to the whole of $X$.

However, there's probably some argument that says that once you have sufficient continuous functions (say, if the space is functionally Hausdorff - i.e. continuous functions to $\mathbb{R}$ separate points) then it would have to be perfectly normal. The difficulty I have with making this into a proof is that there's no requirement that the function $g$ be zero on the complement.

Finally, note that metric spaces are perfectly normal so this supersedes my earlier proof. I leave it up, though, in case it's of use to anyone to see the workings as well as the current state. (Actually, for the record I ought to declare that initially I thought that this was false for almost all spaces. However, once I'd examined my counterexample closely, I realised my error and now I'm having difficulty thinking of a reasonable space where it does not hold.)

1

This isn't a complete answer, but I think that whatever the family is, it contains compact metric (metrisable) spaces. With a paracompactness argument, I suspect that it would extend to locally compact, and I would not be surprised if one could replace "metrisable" by something weaker (though I think that it would need that separation property one-above-normal which I can never remember the name of: namely that every closed set is the zero set of a continuous function).

Here's a proof (I hope): Let $M$ be a compact metric space, $U \subseteq M$ an open subset, $f : U \to \mathbb{R}$ a continuous function. Let's write $K$ for the complement of $U$ in $M$. For each $n \in \mathbb{N}$, let $C_n \subseteq U$ be the subset consisting of points at least distance $1/n$ away from $K$. Then $C_n$ is closed in $M$, hence compact, and $\bigcup C_n = U$. Let $h_0 : M \to \mathbb{R}$ be the "distance from $K$" function (so that $C_n = h_0^{-1}([1/n,\infty))$). Let $V_n$ be the complement of $C_n$.

As $C_n$ is compact, $f$ is bounded on $C_n$. Let $a_n = \max\{|f(x)| : x \in C_n\}$, then $(a_n)$ is an increasing sequence. Let $(b_n)$ be a decreasing sequence that goes to $0$ faster than $(a_n)$ increases, specifically that $(a_nb_n) \to 0$. Let $r : [0,\infty) \to [0,\infty)$ be a continuous decreasing function such that $r(1/n) = b_{n+1}$ (as $(b_n) \to 0$ (this always exists) and let $h = r \circ h_0$. Then for $x \in V_{n-1}$, $h_0(x) \lt 1/(n-1)$ so $h(x) \lt b_n$.

Then $h : M \to \mathbb{R}$ is a continuous function. Moreover, $h f$ (the product, with $h$ restricted to $U$) has the property that for $x \in C_n \setminus C_{n-1} = V_{n-1} \setminus V_n$,

$$|(f h)(x)| = |f(x)| |h(x)| \le a_n b_n$$

Thus as $x \to K$, $(f h)(x) \to 0$ and so we can extend $f h$ to a continuous function $g : M \to \mathbb{R}$ by defining it to be $0$ on $K$.

Then on $U$, $f = g/h$.

(I made this up, so obviously, there may be something I've overlooked in this so please tell me if I'm not correct.)