A generalization of Forelli’s theorem