Fixes #4944 - Makes run_function_once less dangerous

Extracted from https://github.com/Elgg/Elgg/pull/473