We study the ring of polyfunctions over a commutative ring R with unit element, i.e., the ring of functions f:R\to R which admit a polynomial representative p\in R[x] in the sense that f(x)= p(x) for all x\in R. This allows to define a ring invariant s which associates to a commutative ring R with unit element a value in \mathbb N\cup\{\infty\}. The function s generalizes the number theoretic Smarandache function. For the ring R=\mathbb Z/n\mathbb Z we provide a unique representation of polynomials which vanish as a function. This yields a new formula for the number \Psi(n) of polyfunctions over \mathbb Z/n\mathbb Z. We also investigate algebraic properties of the ring of polyfunctions over \mathbb Z/n\mathbb Z. In particular, we identify the additive subgroup of the ring and the ring structure itself. Moreover we derive a new formula for the size of the ring of polyfunctions in several variables over \mathbb Z/n\mathbb Z.