composer require maslosoft/whitelistWhitelist allows you to define allowed PHP functions, variable, classes, and forbid the rest.
By default it also forbids unsafe constructs, like eval, variable variables names, variable methods names.
PHP Code whitelister