Global Variables – Best Practices for Plugin Development

Hello and Good Day!

I’ve been reading various articles on the internet to better understand global variables in PHP, and specifically in WordPress. However, the debate about whether or not to make a variable global in scope has confused me.

I have a use case, in a custom plugin I’ve created, where I’ve repeatedly used current_user variables locally within my functions. I’m not currently passing any variables to any of the functions, and I haven’t made any global variables. My plugin works fine, but there’s a lot of redundant code because of the scope. Do you have any advice or best practice about keeping variables and functions clean and efficient while remaining secure?

Thank you!