In reply to X-Raym.

Your simple 5 line code has zero security. If you want to do something so foolish as to run PHP code from inside a widget, use a widget designed for just that. It's as secure as it can be, for such a non-secure thing to do.

https://wordpress.org/plugins/php-code-widget/

I recommend not using this unless you know exactly what you're doing. But it's there if you need it.